我想做的是:
如果调用了网址http://example.com/foo/foo.php,则应将其重定向为301到http://example.com/bar/foo.php
AND
如果调用url http://example.com/bar/foo.php,它会在内部调用/bar/foo.php脚本,但不会更改(重映射)浏览器URL。
我的规则看起来像这样
RewriteRule ^foo/foo.php(.*) bar/foo.php$1 [R=301]
RewriteRule ^bar/foo.php(.*)$ foo/foo.php$1 [PT]
但是这给了我太多重定向错误。
每个单独激活的规则都有效,但它们似乎一起发生冲突......
答案 0 :(得分:2)
您可以匹配实际请求:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /foo/foo.php
RewriteRule ^foo/foo.php(.*) bar/foo.php$1 [R=301]
RewriteRule ^bar/foo.php(.*)$ foo/foo.php$1 [L]
或完全阻止重写循环:
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^foo/foo.php(.*) bar/foo.php$1 [R=301]
RewriteRule ^bar/foo.php(.*)$ foo/foo.php$1 [L]