0

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.

Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
Brian
  • 3
  • 1
  • 2

1 Answers1

3

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.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
  • Great! Just what I was looking for – Brian Apr 22 '13 at 20:51
  • I did not need to remove all query strings on all redirects, but thx for the tip. I had the problem that the QSD flag got me an error 500 because the QSD flag is for Apache v2.4.0 and later while my host has an older version running. Adding the ? at the end of a rule removed the query strings for that specific rule. :) – bohem.be Jun 24 '15 at 08:35