简体   繁体   中英

Redirect 301 query string htaccess

I've been trying to redirect query string link to another link in my .htaccess file I've been following some guides and I figured out how to do that so at the moment the redirect is done but it doesn't really work like I would like.

This is the first link: http://www.mydomain.it/index.php?page=lkr_pg_chisiamo

That should be redirected to this one: https://www.mydomain.eu/chi-siamo/

This is what I've done in my htaccess in wordpress:

RewriteEngine On

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteCond %{QUERY_STRING} ^page=lkr_pg_chisiamo$
RewriteRule ^(.*)$ https://www.mydomain.eu/chi-siamo/ [R=301,L] 

Now the redirect works but my final URL is: https://www.mydomain.eu/chi-siamo/?page=lkr_pg_chisiamo

What could the problem be?

Now the redirect works but my final URL is: https://www.mydomain.eu/chi-siamo/?page=lkr_pg_chisiamo

You need to discard the query string. Two solutions:

Solution 1 (using ? to reset new query string)

RewriteRule ^(.*)$ https://www.mydomain.eu/chi-siamo/? [R=301,L]

Solution 2 (using QSD flag)

RewriteRule ^(.*)$ https://www.mydomain.eu/chi-siamo/ [R=301,L,QSD] 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM