使用 .htaccess 重定向站点但排除一个文件夹 [英] Redirect site with .htaccess but exclude one folder
问题描述
我想对整个网站进行 301 重定向,但排除 /uploads
文件夹中的所有内容,该文件夹存在于 /root
目录中.
I want to 301 redirect an entire website, but exclude everything in a folder called /uploads
which exists in the /root
directory.
我在谷歌上搜索过这个,但没有想出任何东西,或者我认为我所看到的不正确.
I have googled for this, but didn't come up with anything, or I didn't think what I saw was right.
我们能破解这个吗?
推荐答案
试试这个 mod_rewrite 规则:
RewriteEngine on
RewriteRule !^uploads($|/) http://example.com%{REQUEST_URI} [L,R=301]
此规则匹配任何不以 /uploads
或 /uploads/
开头(前导 /
在模式中丢失,因为在 .htaccess 文件中使用时删除了路径前缀)并将请求重定向到 example.com 上的相应路径.
This rule does match any URL path that does not begin with either /uploads
or /uploads/
(leading /
is missing in the pattern due to the path prefix removal when used in .htaccess files) and redirects the request to the corresponding path at example.com.
这篇关于使用 .htaccess 重定向站点但排除一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!