htaccess重定向index.php没有参数

时间:2011-09-22 12:09:36

标签: .htaccess regex-negation

我正在寻找.htaccess的重定向:

www.mydomain.com/A/和www.mydomain.com/A/index.php没有参数必须重定向到“www.mydomain.com/B /".

www.mydomain.com/A/index.php,参数如www.mydomain.com/A/index.php?id=123即可,不得重定向。

2 个答案:

答案 0 :(得分:3)

您需要使用 mod_rewrite 。您需要确保已安装并启用mod_rewrite。以下是您的网址规则:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^A/(index\.php)?$ http://www.mydomain.com/B/ [NC,R=301,L]

该规则将匹配/A//A/index.php,并且只有在查询字符串为空时才会重定向。

答案 1 :(得分:0)

我认为你可以使用重定向匹配

RedirectMatch "/A/index\.php$" http://www.mydomain.com/B
RedirectMatch "/A/$" http://www.mydomain.com/B
RedirectMatch "/A$" http://www.mydomain.com/B

我希望这会奏效:)

相关问题