views:

71

answers:

1

Hi all,

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]

RewriteRule ^(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!

+1  A: 

Try this rule:

RewriteCond $1 !^(en|nl)$
RewriteRule ^([a-z]{2})/(.*)$ en/$2 [L,R=302]
Gumbo
Seems to work thanks! a lot.But if for some reason www.xxx.com/befr/ is chosen the rewrites failes since /befr/ is more than 2 characters.Is it possible to fix this too?i tried changing your code in:RewriteRule ^([a-z]*?)/(.*)$ en/$2 [L,R=302]But this causes that all images are invisible since they are in a directory (images) that is also rewritten with my adjustments
PimPee
@PimPee: Then where is the limit? Should every request, that does not start with either `/en/…` or `/nl/…` be redirected to `/en/…`?
Gumbo
I was thinking about everything that is not in my exception list, which in that case should contain about 15 folders. Maybe it is a strange solution indeed, since this should not happen if someone uses the website as it is designed for.
PimPee