I have a requirement from a customer to perform some specific redirects (part of decomissioning an old server to a new one). I've been banging my head against this and it's driving me nuts!
In effect, I need to do two .htaccess mod-rewrites at the same time. I'm expecting this will be something really simple, but I've tried everything I can think of so it's time to ask for advice.
I need to do the following:
- URL IN: http://example.com/oldfolder/some-web-resource.html
- URL OUT: http://example.com/newfolder2/some-web-resource/
To further complicate, this is repeated due to the webresources may be in different newfolder locations (newfolder1, newfolder2, newfolder3).
At the moment, my .htaccess segment looks like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond "%{DOCUMENT_ROOT}/oldfolder/%{REQUEST_URI}" -f
RewriteRule "^(.+)" "%{DOCUMENT_ROOT}/newfolder1/$1" [L]
RewriteCond "%{DOCUMENT_ROOT}/oldfolder/%{REQUEST_URI}" -f
RewriteRule "^(.+)" "%{DOCUMENT_ROOT}/newfolder2/$1" [L]
RewriteCond "%{DOCUMENT_ROOT}/oldfolder/%{REQUEST_URI}" -f
RewriteRule "^(.+)" "%{DOCUMENT_ROOT}/newfolder3/$1" [L]
RewriteRule "^" "-" [PT]
This works fine to redirect the folder but it only works if some-web-resource does not already contain the .html.
I have tried:
RewriteRule "%{REQUEST_URI}[^.html]" "%{DOCUMENT_ROOT}/newfolder1/$1" [L]
RewriteRule "^(.*).html$" "%{DOCUMENT_ROOT}/newfolder1/$1" [L]
and many variations on this, but I'm not getting anywhere.