0

I need to rewrite URL with querystring:

http://www.example.com/?p=121&cpage=7

to:

http://www.example.com/

What's the easiest way to do it on .htaccess?

1
  • RewriteRule ^p$ / [L] Commented Aug 22, 2017 at 15:39

1 Answer 1

1

You can achieve that using:

RewriteEngine On
RewriteCond %{QUERY_STRING} p=(.+)$ 
RewriteRule ^(.*)$ http://www.example.com? [R=301,L]

The {QUERY_STRING} will detect the correct query, and if the condition is met it will rewrite it to www.example.com.

The ? at the end of the redirected URL is there so that the query string does not appear on the end of the URL.

Make sure you clear your cache before testing this.

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

4 Comments

thanks, I forgot to mention I need any parameter after "p" to be ignored, basically any URL with ?p= needs to be redirected
I've updated so that anything after the parameter p will now be ignored (so cpage) and it takes any number variable related to p.
I was expermenting with RewriteCond %{QUERY_STRING} p?
Having issues with this @azathoth ? I noticed you removed it as a correct answer.

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.