【问题标题】:htaccess to redirect index.php without parameterhtaccess 重定向 index.php 不带参数
【发布时间】:2011-09-22 12:09:35
【问题描述】:

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

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

带有 www.mydomain.com/A/index.php?id=123 之类的参数的 www.mydomain.com/A/index.php 是可以的,不能重定向。

【问题讨论】:

    标签: .htaccess regex-negation


    【解决方案1】:

    您需要使用 mod_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,并且仅当查询字符串为空时才会重定向。

    【讨论】:

      【解决方案2】:

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

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

      我希望这会奏效:)

      【讨论】:

      • 不——他不能。 RedirectMatch 不适用于查询字符串,因此它将始终被重定向,这不是请求的内容。
      • 哦,好的!我不知道:)
      猜你喜欢
      • 2014-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-28
      • 1970-01-01
      • 1970-01-01
      • 2013-04-07
      相关资源
      最近更新 更多