简体   繁体   中英

htaccess redirect old address to new address not working

I have a problem with redirecting address from : http://www.example.com/za/en/ to http://www.example.com/gb/en/ . It doesn't work now. Thank you.

.htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com/za/en/$
RewriteRule (.*)$ http://www.example.com/gb/en/$1 [R=301,L]

You need this instead:

RewriteEngine On
RewriteRule ^/za/en/(.*)$ /gb/en/$1 [R=301,L]

You cannot match URI in HTTP_HOST variable. You can only match host/domain name there.

You can use this rule:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^za/(en.*)$ /gb/$1 [R=301,L,NC]

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