您好,我有一个网站,应该提供多种语言版本。我是用wordpress做的。我想要实现的是每种语言都有自己的(虚拟)子域。例如 fr.foo.eu 和 nl.foo.eu。
目前我有以下格式的网址:
foo.eu/?lang=nl
foo.eu/?lang=fr
url 中可能有更多内容,例如:
http://hypnose.eu/hallo-wereld/?lang=nl
我想通过以下方式使用 htaccess 获取我的网址:
http://nl.hypnose.eu/hallo-wereld/
你们能帮我实现这个目标吗?
这是我到目前为止在我的 .htaccess 中的内容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^([a-z]{2}\.hypnose\.eu$ [NC]
RewriteCond %{THE_REQUEST} \ /+([^\?]*)\?lang=([a-z]{2})&?([^\ ]*)
RewriteRule ^ http://%2.hypnose.eu/%1?%3 [L,R]
RewriteCond %{QUERY_STRING} !(^|&)lang=
RewriteCond %{HTTP_HOST} ^([a-z]{2})\.hypnose\.eu$ [NC]
RewriteRule ^(.*)$ /$1?lang=%2 [L,QSA]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
最佳答案
尝试在你的 wordpress 规则之上添加:
RewriteCond %{HTTP_HOST} !^([a-z]{2})\.foo\.eu$ [NC]
RewriteCond %{THE_REQUEST} \ /+([^\?]*)\?lang=([a-z]{2})&?([^\ ]*)
RewriteRule ^ http://%2.foo.eu/%1?%3 [L,R]
RewriteCond %{QUERY_STRING} !(^|&)lang=
RewriteCond %{HTTP_HOST} ^([a-z]{2})\.foo\.eu$ [NC]
RewriteRule ^(.*)$ /$1?lang=%1 [L,QSA]
关于wordpress - htaccess 重新定位 url 的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29656108/