【问题标题】:htaccess redirect for www to non-www not workinghtaccess 将 www 重定向到非 www 不起作用
【发布时间】:2016-03-29 03:30:00
【问题描述】:

这让我很生气。由于某种原因,我的域无法将 https-WWW 重定向到 https-non-WWW。这适用于除 https://www.nextoronto.com 之外的所有其他排列

我在 .htaccess 中使用什么代码可以让它适用于所有排列?

编辑:这是现在的重写代码:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.nextoronto\.com [NC]
RewriteRule ^(.*)$ https://nextoronto.com/$1 [L,R=301]

【问题讨论】:

  • 请发布您的 .htccess。
  • #Force non-www: RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.nextoronto\.com [NC] RewriteRule ^(.*)$ nextoronto.com/$1 [L,R=301]

标签: linux wordpress .htaccess redirect url-rewriting


【解决方案1】:

看起来不错,可能是因为前面的其他规则没有达到该规则?

这是我使用的有效方法:

# Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://nextoronto.com/$1 [R=301,L]

# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://nextoronto.com/$1 [R=301,L]

# My other rewrites for routing all requests to index.php go here...

【讨论】:

    【解决方案2】:

    编辑 URL 并尝试使用此代码:

    RewriteEngine on
    rewritecond %{http_host} ^www\.example\.com [nc]
    rewriteCond %{SERVER_PORT} 80 
    rewriterule ^(.*)$ https://example.com/$1 [r=301,nc]
    

    【讨论】:

      【解决方案3】:

      第 1 步

      你应该像这样制作 .htaccess 文件

      重写引擎开启

      RewriteCond %{REQUEST_FILENAME} !-d

      RewriteCond %{REQUEST_FILENAME} !-f

      重写规则 ^(.*)$ index.php?url=$1

      第 2 步

      转到目录,然后查看标记选项文件扩展名。然后查看 .htaccess 文件。

      【讨论】:

        【解决方案4】:

        当没有重写工作时,无论你做什么,考虑一下发生在我身上的事情。我笔记本电脑上的 IIS 或 WAMP 将所有对我的域(称为 example.com)的调用重定向到 localhost。因此,在我的 example.com 服务器上创建所有重写都无济于事,因为对 example.com 的调用从未从我的计算机中取出。只需执行“ping example.com”,如果您的 IP 为 127.0.0.1,请编辑您的 HOSTS 文件。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2019-11-29
          • 2015-09-14
          • 2012-09-25
          • 2018-10-24
          • 2012-11-16
          • 2023-04-02
          • 2011-04-12
          相关资源
          最近更新 更多