因此,我有以下网址:
www.example.com/parent/child1
www.example.com/parent/child2
www.example.com/parent/child3
www.example.com/parent/cool-feature
www.example.com/parent/product
etc...
我需要将所有孩子重定向child2
到一个新域。
到目前为止,我想出了:
RedirectMatch ^/parent(?!/child2) http://www.new-example.com/parent/
这适用于:
www.example.com/parent/child2
但不适用于:
www.example.com/parent/child2/
由于尾部有斜线
无济于事,我试过了:
RedirectMatch ^/parent(?!/child2/) http://www.new-example.com/parent/
RedirectMatch ^/parent(?!/child2\/) http://www.new-example.com/parent/
RedirectMatch ^/parent(?!/child2)/ http://www.new-example.com/parent/
RedirectMatch ^/parent/(?!child2)/ http://www.new-example.com/parent/
正如评论中所提到的那样,您的初始指令本身应能按预期工作。都不存在/parent/child2
,/parent/child2/
或者/parent/child2/anything
应该重定向。
但是,由于您具有“其他指令”,包括“前端控制器”,因此可能会发生冲突。特别是因为您的前端控制器可能使用mod_rewrite,并且RedirectMatch
是mod_alias指令。尽管中的明显顺序,mod_rewrite始终将首先执行.htaccess
。但是这些重定向应该首先在前端控制器之前执行。
尝试将其更改为mod_rewrite重定向,并确保它位于.htaccess
文件顶部附近,且位于前端控制器之前。
RewriteRule ^parent(?!/child2) http://www.new-example.com/parent/ [R=302,L]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句