开发者

htaccess redirect subdomain to php file with get

How can i redirect subdomain to php file with $_GET using htaccess?

For example

en.domain.com => domain.com/index.php?l开发者_高级运维ang=en


Put these directives into your .htaccess in a root folder:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} =en.domain.com
RewriteRule .* http://domain.com/index.php?lang=en [QSA,R=301,L]

This rule will redirect (301, Permanent Redirect) from ANY URL at en.domain.com subdomain to this URL: http://domain.com/index.php?lang=en -- that's exactly what you have asked.


UPDATE: This rule will take subdomain and pass it as a lang parameter to index.php. Right now rule supports 2 language: en (English) or fr (French). Edit this fragment (en|fr) to add/change languages.

RewriteCond %{HTTP_HOST} ^(en|fr)\.domain\.com [NC]
RewriteRule .* http://domain.com/index.php?lang=%1 [QSA,R=301,L]

This rule will redirect from ANY subdomain (can be anything, even jhjaghj77.domain.com). I do not know how many languages you going to have .. but I would recommend the use previous option (when you specify all possible languages manually).

RewriteCond %{HTTP_HOST} ^([a-z0-9]+)\.domain\.com [NC]
RewriteRule .* http://domain.com/index.php?lang=%1 [QSA,R=301,L]


this code works when mod_rewrite is enabled on appache.

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteRule ^.*\.domain.com$ domain.com/index.phph?lang=$1
</IfModule>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜