.htaccess htaccess无参数重定向index.php

.htaccess htaccess无参数重定向index.php,.htaccess,regex-negation,.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的参数是可以的,不能重定向。我想您可以使用重定向匹配来实现这一点 RedirectMatch "/A/index\.php$" http://www.mydomai

我正在查找.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的参数是可以的,不能重定向。

我想您可以使用重定向匹配来实现这一点

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

我希望这能起作用:)

您需要使用mod\u rewrite。您需要确保已安装并启用mod_rewrite。以下是您的URL的规则:

Options +FollowSymLinks
RewriteEngine On

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

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

否--他不能。RedirectMatch不适用于查询字符串,因此它将始终被重定向,这不是请求的。哦,好的!!我不知道:)