I have 3 Domains pointing to the same hosting server, let's say:
example.com
example.net
example.org
Due to Ajax cross-domain issues & captcha, i wanted to force visitors to only access through example.com
while forcing removing www
at the same time. I have a feeling that using htaccess
is the best solution to achieve this.
So basically if calling in the browser any one of the following urls :
www.example.net, www.example.org, example.net, example.org, www.example.com
Should be redirected to example.com
I couldn't find an answer to my exact case, so please be kind and bear with my limited knowledge.
Cheers,
You can use the following in htaccess :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.org$
RewriteRule ^(.*)$ http://example.com/$1 [L,R,NE,NC]
A little improvement :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.(net|org)+$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ http://example.com/$1 [L,R,NE,NC]