如何设置语言

时间:2011-04-26 08:25:26

标签: mod-rewrite

如何使用mod_rewrite设置语言(en,da,de等)?

所有文件都位于同一个目录

设置语言的网址是

?set_lang=da

重写:

www.domain.com/en/index.php                     => www.domain.com/index.php?set_lang=en
www.domain.com/en/another_page.php?cat=black    => www.domain.com/another_page.php?set_lang=en&cat=black

www.domain.com/da/index.php                     => www.domain.com/index.php?set_lang=da
www.domain.com/da/another_page.php?cat=black    => www.domain.com/another_page.php?set_lang=da&cat=black

编辑:

我的.htaccess看起来像这样

RewriteCond %{HTTP_HOST}        ^domain\.net$ [NC]
RewriteRule ^(.*)$              http://www.domain.net/$1 [L,R=301]

RewriteCond %{HTTP_HOST}        ^www\.domain\.net$ [NC]
RewriteCond %{REQUEST_URI}      !^/_domain\.net/ [NC]
RewriteRule ^(.*)$              /_domain.net/$1 [L]

RewriteCond %{HTTP_HOST}        ^(demo|mysql|secure)\.domain\.net$ [NC]
RewriteCond %{REQUEST_URI}      !^/_domain\.net/_(demo|mysql|secure)/ [NC]
RewriteRule ^(.*)$              /_domain.net/_%1/$1 [L]

RewriteCond %{HTTP_HOST}        domain\.net$ [NC]
RewriteCond %{REQUEST_URI}      !^/_domain\.net/ [NC]
RewriteRule ^(.*)$              http://www.domain.net/$1 [L,R=301]

1 个答案:

答案 0 :(得分:0)

我找到了解决方案

RewriteCond %{HTTP_HOST}        domain\.net$ [NC]
RewriteCond %{REQUEST_URI}      ^/(da|en)/(.*)(\?%{QUERY_STRING})?$ [NC]
RewriteRule ^(.*)$              /%2?%{QUERY_STRING}&set_lang=%1 [L]