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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Great! Just what I was looking for
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. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.