仅从 /index.php 的 URL 中删除 QUERY_STRING
我想使用 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,有没有一种简单的方法可以将其记录在某处?
I would like to remove the query string from the URL using mod_rewrite (.htaccess), but only for /index.php
(and not /
).
For example, http://www.example.org/index.php?foo=bar
should redirect to http://www.example.org/index.php
, but http://www.example.org/?foo=bar
should be left alone.
This is my current sutup:
RewriteCond %{QUERY_STRING} !=""
RewriteCond %{REQUEST_URI} ^/index\.php
RewriteRule ^(.*)$ /$1? [R=301,L]
It works, but not with the limitation I want (i.e. it still removes the query string even when index.php
is not in the URL. I think this may have to do with REQUEST_URI realising that /
is being internally redirected to /index.php
, but I can't be sure.
As a side question, I would have a lot easier time working this stuff out if I could work out what value was being used REQUEST_URI, is there an easy way to log this somewhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将此行添加到您的 httpd.conf 来查看发生了什么
You can add this lines to your httpd.conf to see what's going on