Jesse
Jesse

Reputation: 4633

htaccess redirect language folder

I'd like to redirect all incoming requests in a .htaccess file that match the following ruleset.

domain.com -> www.domain.com/en (en is default language)

domain.com/foo -> www.domain.com/en/foo

domain.com/foo?bar=baz -> www.domain.com/en/foo?bar=baz

www.domain.com -> www.domain.com/en
...

If a request contains a language parameter from a given list (en|fr|de) there should be no redirect to 'en'.

Example:

domain.com/de/foo/whatever?bar=baz -> www.domain.com/de/foo/whatever?bar=baz

What I have so far is just the redirect from domain.com to www.domain.com

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

I really hope someone can help. Thanks.

Upvotes: 0

Views: 1326

Answers (1)

bloodyKnuckles
bloodyKnuckles

Reputation: 12089

RewriteCond %{REQUEST_URI} !^/(en|fr|de) [NC]
RewriteRule ^(.*)$ /en/$1 [R=301,L,QSA]

Upvotes: 1

Related Questions