wordpress - htaccess 重新定位 url 的一部分

标签 wordpress .htaccess mod-rewrite

您好,我有一个网站,应该提供多种语言版本。我是用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/

相关文章:

php - 在我的 htaccess 中有太多的 url 重写是一件坏事吗?

apache - 不同的 .htaccess 重写规则取决于 $_GET 参数

Apache mod_rewrite 和 Tomcat 摘要认证

mysql - $wpdb->query WordPress 简码导致语法错误

apache - htaccess 重定向 url 带参数

apache - 多个 TLD - .htaccess 301 重定向

.htaccess - Codeigniter url 用产品名称重写 replacind id

javascript - 用表单替换链接以将变量传递给 javascript/ajax - 单个脚本

php - WordPress 中的 Lumia-bxslider(lumia-bxslider WordPress 插件)

javascript - Chart.js 无法在我的页面上运行?