【发布时间】: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