azathoth
azathoth

Reputation: 573

Apache RewriteRule for querystring

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?

Upvotes: 0

Views: 40

Answers (1)

Joe
Joe

Reputation: 4917

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.

Upvotes: 1

Related Questions