htaccess remove query string

怎甘沉沦 提交于 2019-12-12 02:59:43

问题


I'm not too familiar with regular expressions and I'm having trouble achieving what I want.

The website I'm working on used to have a wordpress blog on it and there are existing links on the internet pointing to http://www.website.com/?p=(random number).

The current code I have right now doesn't seem to work:

RewriteCond %{QUERY_STRING} p=(.*)
RewriteRule http://www.website.com/ [R=301,L]

In fact if there is a way to remove any kind of query string for the index page, that would be even better.

Thanks in advance.


回答1:


If you want to remove all query strings regardless

RewriteCond %{QUERY_STRING} .
RewriteRule ^$ /? [R,L]

This tests if there is any query string . and then redirects to the home page without query string /?.

Never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.



来源:https://stackoverflow.com/questions/16156301/htaccess-remove-query-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!