Redirect htaccess Based On Partial Folder Name - .htaccess

I have a set of dated folders I want to move into one container folder. That is
20011104
20011008
will now be in
archive/20011104
archive/20011104
is there any way to htaccess redirect these in a few lines, rather than one redirect for each. There are hundreds. Is it possible to do a wildcard like 200* such that all such requests get redirected into the archive folder?

Yes, since you know it will start with 200, and will be 8 digits long, you should be able to match with this:
RewriteRule (200\d{5})$ /archive/$1 [L,QSA]
Edit: I'm assuming you're using mod_rewrite

Related

.htaccess rewrite for orphaned URLs containing underscores and arguments

I only modify the .htaccess with great care for the purposes of my online store.
Some time ago, I did a website migration from osCommerce to OpenCart. This resulted in orphaned osCommerce-style URLs with these two example formats:
http://www.londonpower.com/catalog/product_info.php?products_id=75
http://www.londonpower.com/catalog/product_info.php?cPath=15&products_id=75
Lots of websites in internet-land have links to my old-style URLs, and I have about 100 of them, so I would like to redirect them to new URLs with the following format:
http://www.londonpower.com/2-channel-guitar-preamp
If I understand correctly, the problem has two parts:
to eliminate the underscores, as they baffle the .htaccess engine;
to then perform a 301 redirect on the URL.
So far, I have been able to get the first underscore to change to a hyphen, with this Rewrite Rule:
RewriteRule ^([^_]*)_(.*)$ /$1-$2 [R=301,L]
...but no luck with the second underscore (the one that is part of the query string after the "?"). I am stuck there.
I would avoid using rewriting for this. Does the file catalog/product_info.php exist in the new store? If not, create it and add a simple redirection using a map of old IDs to new URLs. If so, do the same thing in a different file, like old-redirector.php then rewrite requests to it.

htaccess rewrite removing consecutive numbers in filenames

I have old urls which contain consecutive numbers I like to redirect via htaccess, for example:
(im not allowed to post links yet)
www.example.com/just/another/path2/name-789-e-11-2.html
www.example.com/its/another/path3/name-789-e-11-5.html
On the new system the appended numbers dont exist anymore:
www.example.com/just/another/path2/name-789-e-11.html
www.example.com/its/another/path3/name-789-e-11.html
So the filename in the different paths is now the same, without the appended consecutive numbers.
Does anybody have a solution for that? I tried different but none of them worked.
Any help would be greatly appreciated.
You can use this redirect rule as first rule in your site root .htaccess:
RedirectMatch 301 ^/(.+\d+)-\d+\.html$ /$1.html

.htaccess rewriting certain word in url

I cannot seem to find the answer to this
I am looking for a .htaccess rewrite way to turn this url
http://www.mydomain.com/Virtuemart.html?keyword=adobe&page=shop.browse
to
http://www.mydomain.com/virtuemart.html?keyword=adobe&page=shop.browse
So basically i just want to change the capital V
There are many pages and variables after the ? so doing it one by one is almost impossible
is their an easy way to do this.
Many thanks for your time
David
Using mod_rewrite (under apache), you can stick something like this in the .htaccess file in your document root:
RewriteEngine On
RewriteRule ^Virtuemart.html /virtuemart.html [L,QSA]
The query string just gets appended to the end untouched. If you want to redirect the browser, add a R=301 flag to the end (or just R if you don't want 301). This makes it so when someone goes to http://www.mydomain.com/Virtuemart.html, they'd actually get served the page at /virtuemart.html.

htaccess removing index.php and search queries from URL

I have a site that, for a certain php function to work, needs the url to be:
/topic/index.php?height=###
I would like the URL to read
/topic/
What can I put in the .htaccess file to achieve this? Can I put one htaccess file in the root, or would I need to put one in each /topic/ directory?
I think the following might work for your issue:
RewriteRule ^([^/]*)/?$ $1/index.php?height=###
Of course, that's assuming a static number. If you need a dynamic number or one provided by the client, you're going to need something like:
RewriteRule ^([^/]*)/(\d+)/?$ $1/index.php?height=$2

Htaccess Image redirect to specific resize directory

Hopefully someone here can point me in the right direction as htaccess is driving me crazy at the moment.
What i am trying to achieve is an automatic redirect for certain images
Currently I use jquery to replace the image src.
The reason for this is the new resized images are in a different directory.
The problem with this method is every time we refresh we have to wait for the dom to fully load.
And I see this is possible with htaccess.
Redirect /my-domain.com/images/image1.png /my-domain.com/images/resized/image1.png
Currently this works, but for over 100 images I really need to find a dynamic solution for this
I tried the following which obviously failed.
RewriteRule ^/my-domain.com/images/(.*) /my-domain.com/images/resized/(.*) [R=301,L]
the resized directory has several directory's so the rule needs to apply to all child directories.
Although it's not a big problem to list all the directories as long as I don't list all images.
hopefully I am missing something simple here, also I wanted to make sure the redirect will not effect SEO?
maybe there is an alternative solution with htaccess?
This is a bit of a messy way to handle images - across multiple folders - but, if that's how you want to manage it, fair enough.
From the above, I understand that:
There are some images within the /images/resized/ folder
There are also some images within subfolders of the same
You want to be able to call a URL within the /images/ folder and have it transcribed to the /images/resize/ folder (with the same end)
In the webroot's .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/images/
RewriteCond %{REQUEST_URI} !^/images/resized/
RewriteRule ^images/(.+)$ /images/resized/$1
Tested OK with this htaccess tester.
"I wanted to make sure the redirect will not effect SEO?"
Filenames are not as important for SEO as alt tags and titles. There should be no change to the SEO stance of your site as a result of this change.

Resources