301 redirection remove parameters

1,021

If you're using Apache ver 2.4 or later then you can use QSD to discard original query string:

RewriteCond %{QUERY_STRING} ^tmpl=component&print=1&page=$ [NC]
RewriteRule ^en/videos/?$ /videos/toutes-les-videos/ [L,NC,R=301,QSD]

On older Apache versions, you can a trailing ? in the target for the same effect:

RewriteCond %{QUERY_STRING} ^tmpl=component&print=1&page=$ [NC]
RewriteRule ^en/videos/?$ /videos/toutes-les-videos/? [L,NC,R=301]
Share:
1,021

Related videos on Youtube

Corentin Branquet
Author by

Corentin Branquet

Updated on December 03, 2022

Comments

  • Corentin Branquet
    Corentin Branquet over 1 year

    I want to redirect this url :

    http://loremipsum.com/en/videos?tmpl=component&print=1&page=
    

    to

    http://loremipsum.com/videos/all-videos/
    

    So I write this 301 redirection :

    RewriteCond %{QUERY_STRING} ^tmpl=component&print=1&page=$
    RewriteRule ^en/videos$ /videos/all-videos/ [L,R=301]
    

    It's redirect but , the url keeps all parameters :

    http://loremipsum.com/videos/all-videos/?tmpl=component&print=1&page=
    

    What I want is to remove these parameters.

    Thanks for your help !

    • arkascha
      arkascha almost 7 years
      When will people finally start to read the documentation of the tools they use?