htaccess remove query string

2019-09-08 11:16发布

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条回答
贼婆χ
2楼-- · 2019-09-08 12:03

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.

查看更多
登录 后发表回答