Question

First of all I will say that I search for solution but I didn't found working answer :(

I have 1 project in 1 root folder with multiple subdomains (language versions):

en.sitedomain.com

de.sitedomain.com

fr.sitedomain.com

And I have a www.sitedomain.com version.

I need to make a redirect when someone goes to sitedomain.com (without any subdomain) to be redirected to www.sitedomain.com

I tried with something as:

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

But I got wrong redirects

subdomain.com ==>> www.subdomain.com  CORRECT
www.subdomain.com ==>> www.subdomain.com  CORRECT 
en.subdomain.com ==>> www.en.subdomain.com  WRONG !!!
de.subdomain.com ==>> www.de.subdomain.com  WRONG !!! 

Can anyone help me please :)

Was it helpful?

Solution

What you only have to do is this: verify if HTTP_HOST is equals to sitedomain.com.
If it is then redirect to www.sitedomain.com.

Try the following (i've omitted https part)

RewriteCond %{HTTP_HOST} ^sitedomain\.com$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top