【问题标题】:htacces opencart redirect https not work corectlyhtaccess opencart 重定向 https 无法正常工作
【发布时间】:2020-01-16 04:29:43
【问题描述】:

在我重定向到 https 后,一些链接不再起作用:

例如: 域/类别 - 没关系 域/产品 - 没关系 域/类别/产品 - 不起作用 域/类别/类别/产品 - 不起作用

页面似乎没有加载 CSS,只是链接。

谁能帮助我提供解决此问题的建议、代码、示例?

非常感谢。

RewriteEngine On
RewriteBase /

 ### Ptr SSL
 #RewriteCond %{HTTP_HOST} !^www.
 #RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
 #RewriteCond %{HTTPS} !=on
 #RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

 RewriteCond %{HTTPS} !=on   
 RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 #end SSL

 RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
 RewriteRule ^googlebase.xml$ index.php?route=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]

【问题讨论】:

    标签: ssl mod-rewrite opencart opencart2.x opencart-module


    【解决方案1】:

    以下是我的网站之一:

    RewriteBase /
    
    # SSL & www
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
    
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # end SSL & www
    
    RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
    RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
    RewriteRule ^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]
    

    我还在设置中将“SSL”设置为“是”,并启用了 SEO URL。我知道这两个重写条件可以被压缩,但是当我这样做时我的网站会中断,所以我很乐意让它们保持原样

    编辑看到您对站点 URL 的评论后,问题似乎不是 .htaccess 而是页面的 <base> 元素的 src 值是 "(unknown)" 这是元素包含所有相对链接的站点的基本 URL。

    因此,404 错误表明浏览器假定“SEO 友好”类别名称是一个真正的子文件夹,并且 css 文件存储在那里。换句话说,它认为有一个名为“public_html/Accesorii”的文件夹,并且 css 文件在那里。

    你需要做的是查看主题设置或手动编辑head.php文件,它应该在/catalog/view/theme/fastor/common/文件夹中的某个地方。

    【讨论】:

    • 您好,感谢您的回复。我测试了你的代码,但我得到了相同的结果。商店的类别不加载,缺少 CSS,它只显示链接。有谁知道这个模块是否可以解决问题 - opencart.com/index.php?route=marketplace/extension/… 谢谢。
    • 这很奇怪,我的类别/子类别/子类别/产品工作得很好。控制台中的错误说明了什么?
    • @LiviuVasile 我已更新我的答案以引用此信息。我建议从这些 cmets 中删除您的网站 URL,只是为了您自己的隐私
    • 我成功使用了基本 href,现在我在网站的所有页面上都有基本 href。但我仍然有加载 css 的问题。当我使用 ssl 直接在浏览器中访问链接 css 时,在控制台中我收到:加载资源失败:服务器响应状态为 404(未找到)控制台中的所有链接都是:xGET domain/Accesorii/catalog/view/theme/fastor/css/bootstrap.cssnet::ERR_ABORTED 404(未找到),...所有链接都相同
    • 这很奇怪,当我测试 url 时,我看不到基本 href 的值。试试这个 URL domain/Accesorii/Bratari 并查看 <head>
    猜你喜欢
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 2013-01-08
    • 2013-11-04
    • 2023-04-02
    • 2018-12-12
    • 1970-01-01
    相关资源
    最近更新 更多