Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache (/.*)的URL重写循环_Apache_Loops_Mod Rewrite - Fatal编程技术网

Apache (/.*)的URL重写循环

Apache (/.*)的URL重写循环,apache,loops,mod-rewrite,Apache,Loops,Mod Rewrite,当我点击时,我必须访问以下url: localhost/b/c redirect to localhost/a/b/c 我尝试了这个重写规则: RewriteCond [%{REQUEST_URI}] !^/?(a(/.*))/?$ RewriteRule ^/([A-Za-z0-9_]+)/?$ /a/$1 [R,L] 但它只适用于localhost/b。不适用于localhost/b/c即多个级别 RewriteCond [%{REQUEST_URI}] !^/?(a(/.*))/?$

当我点击时,我必须访问以下url:

localhost/b/c
redirect to
localhost/a/b/c
我尝试了这个重写规则:

RewriteCond [%{REQUEST_URI}] !^/?(a(/.*))/?$
RewriteRule ^/([A-Za-z0-9_]+)/?$ /a/$1 [R,L]
但它只适用于
localhost/b
。不适用于
localhost/b/c
即多个级别

RewriteCond [%{REQUEST_URI}] !^/?(a(/.*))/?$
RewriteRule ^/(.*)/?$ /a/$1 [R,L]
此规则正在循环并重写到url

localhost/a/a/a/a/a/a/a/a/a/a/a/b/c

非常感谢您的帮助。我不熟悉url重写

也许这对你来说是可行的:

    RewriteCond %{REQUEST_URI} !^/?a/.*/?$
    RewriteRule ^/(.*) /a/$1 [R,L]
我认为您的问题在于您在
RewriteCond
中使用
[]
,而它应该是
{}

此外,启用也有助于调试重写规则


希望它能帮助你前进

现在我有了另一个问题:这个规则在chrome和mozilla上有效,但在IE上不起作用。有什么解决方案吗?试着启用RewriteLog,看看在使用IE时请求是否不同。我不知道IE为什么不重定向。缓存可能有问题。我不确定它是否有帮助,但您可以尝试使用
[R=301,L]
。我总是在尝试新的重写规则之前删除缓存,而且[R=301,L]不工作。我在IE8中尝试过,它工作得很好。如果服务器上不存在
a/b/c
,并且您尝试获取
b/c
,您将不会在浏览器中看到
a/b/c
url,它仍然显示
b/c
。这与铬不同。但是,如果它存在,重定向工作正常。查看
RewriteLog
我发现,在这两种情况下,重写都达到了预期效果。也许你也有同样的“问题”?