Reputation: 3162
I have this bit of code in my .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?oldomain\.com [NC]
RewriteCond %{REQUEST_URI} ^/files(/.*)?$ [NC]
RewriteRule ^ http://archive.newdomain.com%{REQUEST_URI} [R=301,L]
Right now, if I access www.oldomain.com/files/document.pdf
it redirects me to archive.newdomain.com/files/document.pdf
.
This is not what I want. I need to get redirected to archive.newdomain.com/document.pdf
(whitout the /files/ folder).
What changes should I make?
Upvotes: 1
Views: 20
Reputation:
Your code is almost doing that already, just change it to:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?oldomain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/files(/.*)?$ [NC]
RewriteRule ^ http://archive.newdomain.com%1 [R=301,L]
Using %1
, which you were already capturing but not using.
Don't forget to clear your browser cache before testing since the previous redirects that you visited will be cached.
Upvotes: 1