使用 mod_alias 重定向文件夹的问题
-
21-09-2019 - |
题
接下来的另一个问题 这个线程. 。我唯一无法解决的剩余问题是,有一个现在不存在的文件夹“/team/”的列表,但是如果我将其添加到我的 .htaccess 文件中,它会破坏以下文件中的所有其他 .htaccess 条目该文件夹,即
redirect 301 /team/ /team.html
redirect 301 /team/joe_bloggs.htm /team.html
redirect 301 /team/joe_bloggs.html /team.html
redirect 301 /team/bill_smith.htm /team.html
redirect 301 /team/bill_smith.html /team.html
如果我随后尝试访问 /team/joe_bloggs.htm,我将需要
/team.html/joe_bloggs.htm
如果我能解决这个问题,它可能会帮助我了解如何解决我原来的问题并减少我的 .htaccess 文件中的大量重定向页面列表,因此非常感谢您的帮助。
解决方案
您需要更改顺序,然后输入“redirect 301 /team/ /team.html
“ 在最后。它逐行读取,如果发现合适的内容,就会替换它。
此外,我认为你需要学习添加、^和$字符。^ 表示表达式应该开始,$ 表示表达式应该结束。所以, ^/team/$
意思是,它应该完全是 /team/ 并且不会匹配 /team/joe_bloggs.htm
其他提示
这 Redirect
指示 适用于路径前缀。在这种情况下,第一个指令中使用的路径前缀(/team/
) 匹配,路径的其余部分将附加到新的 URL 路径。
[...] 任何以以下开头的请求
URL-Path
将向目标位置的客户端返回重定向请求URL
. 。匹配之外的附加路径信息URL-Path
将被附加到目标URL
.
尝试 RedirectMatch
反而:
RedirectMatch 301 ^/team/ /team.html
不隶属于 StackOverflow