apache重定向中的精确Url匹配

apache重定向中的精确Url匹配,apache,.htaccess,mod-rewrite,redirect,Apache,.htaccess,Mod Rewrite,Redirect,我有一个重写,需要匹配如下 /test ---No Match and no redirect /test/ ---No Match and no redirect /test/* --Match and redirect. It should match only for this. 我已经编写了一个重定向规则,该规则与上述所有Ocuurance匹配 RewriteRule ^/test/(.+)$ http://test.se/abcd/$1

我有一个重写,需要匹配如下

/test          ---No Match and no redirect
/test/         ---No Match and no redirect
/test/*        --Match and redirect. It should match only for this.
我已经编写了一个重定向规则,该规则与上述所有Ocuurance匹配

RewriteRule ^/test/(.+)$ http://test.se/abcd/$1 [NC,R=301,L]

请建议以上规则仅与/test/anytext匹配。

您拥有的规则是您想要的,但由于它位于htaccess文件中(我假设),您需要去掉前导斜杠:

RewriteRule ^test/(.+)$ http://test.se/abcd/$1 [NC,R=301,L]
并确保已加载mod_rewrite,且重写引擎已打开:

RewriteEngine On

非常感谢。您还可以修改重定向规则taht,以便只匹配/test和/test/to/home/mytest/index。html@Patan您的意思是类似于
重写规则^test/?$/home/mytest/index.html[L]
?谢谢。现在我们在生产中有了同样的规则。它还重定向/test和/test/to。我不确定是否有其他规则导致这种情况。你能帮我一下吗。