dongping6974
dongping6974
2016-03-09 16:22

3 tlds:强制只有一个+用htaccess删除www

已采纳

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,

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • douxiluan6555 douxiluan6555 5年前

    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]
    
    点赞 评论 复制链接分享
  • dongshanni1611 dongshanni1611 5年前

    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]
    
    点赞 评论 复制链接分享