如何使用要重新定向所有,但一个子目录
题
它已经有一段时间,因为我已经搞砸了.就和我似乎无法得到这一相当正确的。我有一个网站,说example.com,我在那里想要的example.com/*重定向到example.com/collector.html 除了 对于网址下子目录example.com/special我想继续工作。
例如:
- example.com/page.html 应该重定向到example.com/collector.html
- example.com/foo/bar 应该重定向到example.com/collector.html
- example.com/special/page.html 不应该重定向
我会想到这样的东西
RedirectMatch 302 ^/[^(special)]/.* /collector.html
RedirectMatch 302 ^/[^(collector.html)/]* /collector.html
就可以做到的,但它不起作用我想要的方式。
解决方案
也许这个吗?(需要mod_rewrite)
RewriteEngine On
RewriteRule !^(special(/.*)?|collector\.html)$ collector.html [R,L]
其他提示
这个工作对我来说在阿帕奇2.2.13我重新创建的目录结构你的描述。
RedirectMatch 302 /(?!special) http://www.example.com/collector.html
该模式在括号内说不匹配的,如果URI包含string'特别'.
还有国防部重写是不是总是可用和在这种情况下是不必要的。
试试这个:
RedirectMatch 302 /\/[^(special)]\/.+/ /collector.html
RedirectMatch 302 /\/[^(collector\.html)]/ /collector.html
也许...?
RewriteEngine on
RewriteRule ^(?!special) collector.html [R,NC]
不隶属于 StackOverflow