Home > Net >  Redirection with parameters and multiple query
Redirection with parameters and multiple query

Time:03-22

I want to redirect this url https://www.mydomain.fr/mon-compte-membre/?ihcnewlevel=true&lid=7&urlr=https://www.mydomain.fr/services/

To `https://www.mydomain.fr/slug/

EDIT This is the edited code (still not working)

<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} ^/mon-compte-membre/ [NC]
RewriteCond %{QUERY_STRING} ihcnewlevel=true [NC]
RewriteCond %{QUERY_STRING} lid=7 [NC]
RewriteCond %{QUERY_STRING} urlr=https://www\.mydomain\.fr/services/ [NC]
RewriteRule ^ /slug/ [R=302,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

CodePudding user response:

  1. You must use ? in the target to strip off any previous query string
  2. Apache won't decode % characters in query string so you will have to match them literally

You may use:

RewriteCond %{THE_REQUEST} /mon-compte-membre/ [NC]
RewriteCond %{QUERY_STRING} (^|&)ihcnewlevel=true(&|$) [NC]
RewriteCond %{QUERY_STRING} (^|&)lid=7(&|$) [NC]
RewriteCond %{QUERY_STRING} (^|&)urlr=https://www\.mydomain\.fr/services/ [NC]
RewriteRule ^ /slug/? [R=302,L]

Once you're satisfied with the result, replace 302 with 301.

CodePudding user response:

With your shown samples, please try following htaccess rules file. Please make sure that you put these rules above rules for rewrite(in backend) in case you have any.

Also make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/mon-compte-membre/\?ihcnewlevel=true&lid=7&urlr=https://www\.mydomain\.fr/services/\s [NC]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.fr$ [NC]
RewriteRule ^ https://www.mydomain.fr/slug/ [R=301,L]
  • Related