简体   繁体   中英

Remove folder from htaccess

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM