kimomat
kimomat

Reputation: 2399

Redirect permanent with additional params

My goal is to redirect from /kontaktaufnehmen/kontakt.html to /auftragsverwaltung/kontakt/?type=1 and the parameters must be added to the new path.

I tried

Redirect permanent /kontaktaufnehmen/kontakt.html /auftragsverwaltung/kontakt/?type=1

but the parameters are not added to the redirected path. Without ?type=1 the parameter will be added.

Upvotes: 0

Views: 456

Answers (1)

Jon Lin
Jon Lin

Reputation: 143906

Try:

RewriteEngine On
RewriteCond %{QUERY_STRING} !type=1
RewriteRule ^/?kontaktaufnehmen/kontakt.html /auftragsverwaltung/kontakt/?type=1 [L,R=301,QSA]

RewriteCond %{QUERY_STRING} type=1
RewriteRule ^/?kontaktaufnehmen/kontakt.html /auftragsverwaltung/kontakt/ [L,R=301]

The important thing here is the QSA flag, which means whatever query string that's already there gets appended. The mod_alias directive Redirect won't do this for you. The second rule is simply a redirect because it sees that the type=1 query string is already there so it won't add another.

Upvotes: 1

Related Questions