【问题标题】:Htaccess - Rewrite from http to https and www to non-wwwHtaccess - 从 http 重写为 https 和 www 重写为非 www
【发布时间】:2015-01-10 22:13:00
【问题描述】:

我正在尝试将表单 http 重写为 https 并将 www 重写为非 www url。

基本上,如果有人转到http://www.example.com,他们需要被重定向到https://example.com 和所有其他错误网址实例(http://example.com 等)。

我试图通过将建议拼凑在一起来做到这一点:

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

但是当我在重定向检查器中检查 URL 时,我得到了错误...http://garrysun.com 工作正常并转到 https://garrysun.comhttp://www.garrysun.com 得到这个:

查看链接:http://www.garrysun.com 重定向类型:301 永久移动 重定向到:https://garrysun.com/https://www.garrysun.com

如何更正我的重写代码?

附: - 我正在使用 OpenCart 1.5.4,并且我在新东西之上还有以下重写代码(不知道它是否会影响任何东西):

RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

【问题讨论】:

    标签: .htaccess redirect url-rewriting rewrite url-redirection


    【解决方案1】:

    您可以针对该要求使用这条规则:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule ^ https://garrysun.com%{REQUEST_URI} [NE,L,R=301]
    
    # rest of your rules will appear below
    

    【讨论】:

      猜你喜欢
      • 2014-12-16
      • 2017-12-04
      • 1970-01-01
      • 1970-01-01
      • 2011-09-15
      • 2015-06-18
      • 2014-05-02
      • 1970-01-01
      • 2017-01-02
      相关资源
      最近更新 更多