Jonathan
Jonathan

Reputation: 2073

htaccess 301 redirect GET-Parameter and remove it

I am in a need of a 301-Redirect with the following example:

The pages

Should be redirected to

but i really do not understand how to solve that.

What i have tried:

RewriteCond %{query_STRING} ^id=(.*)$
RewriteRule https://www.example.com/ [R=301,L]

Upvotes: 1

Views: 894

Answers (1)

anubhava
anubhava

Reputation: 786359

You need to use ? at the end of target URI to strip off any existing query string. Also you can use a relative target URI also if target is on same domain.

Use this rule:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^id= [NC]
RewriteRule ^(?:index\.php)?$ /? [R=301,L,NC]

Upvotes: 2

Related Questions