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]
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.phpI 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]
精彩评论