如何重定向www添加域到非www?-我认为它';it’这比标题看起来要复杂一些


How to redirect www add on domain to non www? - I think it's a bit more complex than the title may make it seem

正如标题所述,我正在尝试301将网站的wwww版本重定向到非www。简单吧?好吧,我已经尝试了很多事情,但最终还是做不到。我认为我的情况比乍一看要复杂一些,所以我会在下面尽可能多地提供细节。

有3个域托管在同一服务器上:主域:example.com加载项域:example.com.au附加域:example.com.mx

主域https://example.com确实正确设置了从https://www.example.comhttps://example.com的301。所以没有问题。但是,加载项域example.com.auexample.com.mx没有设置301重定向。此外,对于这两个附加域,当您访问它们的页面时,www版本会显示以下消息:

您的连接不是专用

攻击者可能试图从www.example.com.au(例如,密码、消息或信用卡卡片)。

很抱歉我是一个傻瓜,但不确定这些细节是否重要。但我想我无论如何都应该提供它们以防万一。

所有的域都在同一个平台上-Magento所有域共享相同的文档根文件夹,当然共享相同的.htaccess文件

我尝试了一些不同的htaccess文件,但不幸的是什么都不起作用。。。我也试过在cPanel中进行重定向,但什么也没发生。任何提示或建议都将不胜感激!!

我假设您使用https访问所有域,因此SSL证书可能存在问题。确保您拥有两个附加域的通配符(*.example.com.au和*.example.com.mx)证书。

以下是如何在cPanel中进行操作的说明。

在.htaccess 中

  RewriteEngine on
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  RewriteCond %{HTTP_HOST} .
  RewriteCond %{HTTP_HOST} !^www'. [NC]
  RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  RewriteCond %{HTTP_HOST} ^www'.(.+)$ [NC]
  RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]