开发者

Multilanguage site, subdirectories as language (RewriteRule)

For my website i want to rewrite my url to:

www.xxx.com/en/index.php instead of www.xxx.com/index.php?language=en

www.xxx.com/nl/index.php instead of www.xxx.com/index.php?language=nl

www.xxx.com should be www.xxx.com/en/

This actually works i have added these rewrite rules

RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www\.xxx\.com(\/?)$

RewriteRule (.*) http://www.xxx.com/en/$1 [R=302,L]

RewriteRu开发者_JAVA技巧le ^(nl|en)/(.*)$ $2?language=$1&%{QUERY_STRING} [L]

The R=302 is added for testing purposes

Are the above given RewriteCond and RewriteRule good enough or are there other, maybe shorter or better ways to rewrite .com/ to .com/en/

If the url is edited to a language that does not exists i want this user to be redirect to english.

Example

www.xxx.com/es/index.php is requested, this language does not exists or no language is given i want the user to be redirect to www.xxx.com/en/index.php

I tried the following:

RewriteRule ^([^n][^l]|[^e][^n])/(.*)$ en/$2%{QUERY_STRING} [L,R=302]

This works in some cases but if www.xxx.com/ne/index.php is entered it is considered as valid and not rewritten. www.xxx.com/index.php is also not rewritten to www.xxx.com/en/index.php

Could someone help me to fix this?

Thanks in advance!


Try this rule:

RewriteCond $1 !^(en|nl)$
RewriteRule ^([a-z]{2})/(.*)$ en/$2 [L,R=302]
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜