简体   繁体   中英

.htacces multi-language redirect

I have a strange problem with .htaccess and google. I have multiple-different root domain with 301 redirection to main domain, and that's ok, but i have also multiple languages like so .com/sl, .com/it, .com/en, and .net/sl, .net/it, .net/en the problem is when you click on the link from google is wwww.old-domain.com/sl and that's right, but when you click on it the url become like this www.new-domain. comsl so the slash is missing and of course the page does not work.

So is there a fix in htaccess? my htacces redirects are:

RewriteCond %{HTTP_HOST} ^old-domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old-domain.com/$ [OR]
RewriteCond %{HTTP_HOST} ^old-domain.net/$ [OR]
RewriteCond %{HTTP_HOST} ^www.old-domain.net$
RewriteRule ^(.*)$ "http\:\/\/www\.new-domain\.com$1" [R=301,L]

So I have to fix this www.old-domain.comsl to www.new-domain.com/sl

Thanks to all.

I think you forgot a slash.. Try this?

RewriteCond %{HTTP_HOST} ^old-domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old-domain.com/$ [OR]
RewriteCond %{HTTP_HOST} ^old-domain.net/$ [OR]
RewriteCond %{HTTP_HOST} ^www.old-domain.net$
RewriteRule ^(.*)$ "http\:\/\/www\.new-domain\.com\/$1" [R=301,L]

You should not need the trailing / in your RewriteCond . Furthermore, you are escaping incorrectly (you need to do it in the opposite places).

Clean it up with the following and see if it solves your issue.

RewriteCond %{HTTP_HOST} ^old-domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.old-domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^old-domain\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.old-domain\.net$
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,L]

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