我已经为此奋斗了数周,但无法找到解决方案,我必须在多语言网站的 .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]
非常感谢!!!
最佳答案
根据您显示的示例,您可以尝试以下操作吗?请确保在测试您的网址之前清除浏览器缓存。
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]
关于apache - .htaccess - 将域/lang/重定向到每种语言的子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65778994/