.htaccess语言子域的重定向规则

时间:2014-06-20 11:41:33

标签: regex apache .htaccess mod-rewrite

除了上一篇文章中的htaccess规则之外 - .htaccess redirect rule for subdomains 我需要添加“en”子域的规则。

例如,我有以下网址结构:

en.example.com
someword.en.example.com

it.example.com
someword.it.example.com

其中“en”和“it”是语言定义。 “en”是网站上的默认语言,因此我想自动将域中包含“en”的所有请求重定向到没有“en”的域,例如:

en.example.com -> example.com
someword.en.example.com > someword.example.com

但所有其他语言应保留在网址中。我只需要“en”。

你可以帮我解决这个案子的.htaccess规则吗?感谢。

1 个答案:

答案 0 :(得分:2)

您可以使用:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^en\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]

RewriteCond %{HTTP_HOST} ^([^.]+)\.en\.(.+)$ [NC]
RewriteRule ^ http://%1.%2%{REQUEST_URI} [NE,R=301,L]
相关问题