【问题标题】:How to redirect all www to non-www and SSL Url in Opencart?如何将所有 www 重定向到 Opencart 中的非 www 和 SSL Url?
【发布时间】:2018-02-08 08:39:41
【问题描述】:

我在处理 url 时遇到了我的 opencart 网站问题。

The problems are like - 
1. When I use http://example.com : It works fine.
2. When I use https://example.com : It works fine with my non-www ssl certificate
3. When I use http://www.example.com : I lose my styles.
4. When I use https://www.example.com : I lose my styles and works as secured page

Now I want it in these ways :
1. When I use http://example.com : It should redirect to https://example.com
2. When I use http://www.example.com : It should redirect to http://example.com so that I can't lose styles.
3. When I use www.example.com : It should redirect to https://example.com
4. When I use only example.com : It should redirect to https://example.com

这是我当前的 .htaccess.txt

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/download/(.*) index.php?route=error/not_found [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]
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]

请指导我如何实现我想要的以及如何解决样式问题。 提前致谢!

【问题讨论】:

    标签: .htaccess ssl url opencart


    【解决方案1】:

    试试这个(替换 .htaccess 文件的最后三行):

    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP:X-Forwarded-SSL} on
    RewriteCond %{REQUEST_URI} !^/checkout/?.*$
    RewriteRule ^(.*)$ http://url.com/$1 [R=301,L]
    

    并确保您的 opencart SSL 设置已打开且正确的 https:// URL 到位。

    如果上述解决方案不起作用,您可以简单地将 www 的所有调用重定向到非 www url,您的网站可以完美地与 SSL 和样式一起使用。

    【讨论】:

      【解决方案2】:

      你可以试试我的解决方案。他在 2020 年工作。

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

      【讨论】:

        猜你喜欢
        • 2016-04-02
        • 1970-01-01
        • 2017-09-23
        • 2014-11-24
        • 2011-06-24
        • 2019-03-09
        • 2011-11-05
        • 2013-12-20
        • 1970-01-01
        相关资源
        最近更新 更多