Remove QUERY_STRING from URL only for /index.php
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.ex开发者_Go百科ample.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?
You can add this lines to your httpd.conf to see what's going on
RewriteLog /path/to/log
RewriteLogLevel 5
加载中,请稍侯......
精彩评论