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

.htaccess - Redirect domain/lang/ to subdomain for each language

我已经为此苦苦挣扎了数周,但我无法找到解决方案,我必须在一个多语言网站的 .htaccess 中进行重定向,该网站的所有页面都遵循相同的结构,但具有每种语言的子域。以下方式对http有效为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

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

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 之前清除浏览器缓存。

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