alexanoid
alexanoid

Reputation: 25790

.htaccess redirect rule for language subdomain

In additional to htaccess rules from my previous post -.htaccess redirect rule for subdomains I need to add rule fo "en" subdomain.

For example I have following url structures:

en.example.com
someword.en.example.com

it.example.com
someword.it.example.com

where "en" and "it" is a language definition. "en" is a default language on the site, so I'd like to automaticaly redirect all requests that contain "en" in domains to domains without "en", for example:

en.example.com -> example.com
someword.en.example.com > someword.example.com

but all other languages should remain in url. I need it only for "en".

Could you please help me with .htaccess rule for this case ? Thanks.

Upvotes: 1

Views: 130

Answers (1)

anubhava
anubhava

Reputation: 785128

You can use:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^en\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]

RewriteCond %{HTTP_HOST} ^([^.]+)\.en\.(.+)$ [NC]
RewriteRule ^ http://%1.%2%{REQUEST_URI} [NE,R=301,L]

Upvotes: 2

Related Questions