.htaccess - 将域/lang/重定向到每种语言的子域

问题描述:

数周以来,我一直在为此苦苦挣扎,但无法找到解决方案,我必须在多语言网站的 .htaccess 中进行重定向,该网站的所有页面都遵循相同的结构,但有一个子域每种语言.以下方式对 http 作为 https 有效:

I've been struggling with this for weeks and I can't get to the solution, I have to make a redirect in .htaccess of a multi-language website with all its pages following the same structure but with a subdomain for each language. In the following way that is valid for http as https:

domain.es/es/allpages  to  es.subdomain.com/allpages
domain.es/pt/allpages  to  pt.subdomain.com/allpages
domain.es/de/allpages  to  de.subdomain.com/allpages
domain.es/fr/allpages  to  fr.subdomain.com/allpages
domain.es/en/allpages  to  eu.subdomain.com/allpages

有什么想法吗?我尝试了以下但不确定它是否正确:

Any ideas? I have tried the following but not sure if it is correct:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/es/(.*)$
RewriteRule ^(.*) https://es.subdomain.com/%1 [R=301,NC]

RewriteCond %{REQUEST_URI} ^/pt/(.*)$
RewriteRule ^(.*) https://pt.subdomain.com/%1 [R=301,NC]

RewriteCond %{REQUEST_URI} ^/fr/(.*)$
RewriteRule ^(.*) https://fr.subdomain.com/%1 [R=301,NC]

RewriteCond %{REQUEST_URI} ^/de/(.*)$
RewriteRule ^(.*) https://de.subdomain.com/%1 [R=301,NC]

RewriteCond %{REQUEST_URI} ^/en/(.*)$
RewriteRule ^(.*) https://eu.subdomain.com/%1 [R=301,NC]

非常感谢!!!!

根据您显示的示例,您能否尝试以下操作.在测试 URL 之前,请确保清除浏览器缓存.

Based on your shown samples, could you please try following. Please make sure you clear your browser cache before you test your URLs.

RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain\.es$ [NC]
RewriteRule ^(es|pt|de|fr|en)/(.*)/?$ http://$1.subdomain.com/$2 [NE,R=301,NC,L]