【问题标题】:Remove QUERY_STRING from URL only for /index.php仅为 /index.php 从 URL 中删除 QUERY_STRING
【发布时间】:2011-10-13 22:47:37
【问题描述】:

我想使用 mod_rewrite (.htaccess) 从 URL 中删除查询字符串,但仅适用于 /index.php(而不是 /)。

例如,http://www.example.org/index.php?foo=bar 应该重定向到 http://www.example.org/index.php,但应该不理会http://www.example.org/?foo=bar

这是我目前的sutup:

RewriteCond %{QUERY_STRING} !=""
RewriteCond %{REQUEST_URI} ^/index\.php
RewriteRule ^(.*)$ /$1? [R=301,L]

它可以工作,但不受我想要的限制(即,即使index.php 不在 URL 中,它仍然会删除查询字符串。我认为这可能与 REQUEST_URI 意识到 / 正在内部重定向有关到/index.php,但我不能确定。

作为一个附带问题,如果我可以计算出正在使用的 REQUEST_URI 值,我会更轻松地解决这些问题,是否有一种简单的方法可以在某处记录它?

【问题讨论】:

    标签: apache .htaccess mod-rewrite apache2 query-string


    【解决方案1】:

    您可以将此行添加到您的 httpd.conf 以查看发生了什么

    RewriteLog /path/to/log
    RewriteLogLevel 5
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      • 2014-10-28
      • 2012-06-15
      • 2011-05-20
      • 2012-09-21
      相关资源
      最近更新 更多