简体   繁体   English

从 htaccess 中删除文件夹

[英]Remove folder from htaccess

I have this bit of code in my .htaccess file:我的 .htaccess 文件中有这么一段代码:

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 .现在,如果我访问www.oldomain.com/files/document.pdf它会将我重定向到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) .我需要重定向到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.使用%1 ,您已经在捕获但未使用。

Don't forget to clear your browser cache before testing since the previous redirects that you visited will be cached.不要忘记在测试之前清除浏览器缓存,因为您访问的先前重定向将被缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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