php - Opencart 2.2.x ssl 用于所有请求

标签 php .htaccess ssl opencart

我安装了 opencart 最新版本,我想为 url 启用所有 ssl

在管理员中设置 SSL 启用

在 config.php 中,admin 和 category 都更改为 https

访问权限

RewriteEngine On
RewriteBase /

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]

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

但是当 url 不是 SEO 时它工作所以 url 与 SEO 它不起作用 网址将是 https://www.localhost/index.php?route=desktops/mac

如何改成 https://www.localhost/desktops/mac

最佳答案

我还安装了 opencart 2.2。

我尝试了 https 的扩展,但它崩溃了;(

我找到了一个可行的解决方案 3 个步骤:

•• 1 •• 在 .htaccess 中:在末尾添加

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} store 
RewriteRule ^(.*)$ https://www.__your_domain__.com/store/$1 [R,L]

•• 2 ••
在 root + admin 的 config.php 中

<?php
// HTTP
define('HTTP_SERVER', 'https://www.__your_domain__.com/store/');

// HTTPS
define('HTTPS_SERVER', 'https://www.__your_domain__.com/store/');

**** 即使在浏览器中使用 https://也是不够的....在源代码中每个链接都是 http://.... **** 所以我找到了最后一步


•• 3 •• 在系统/图书馆/网址 将 http 修改为 https 和 voilà :)

public function link($route, $args = '', $secure = false) {
        if ($this->ssl && $secure) {
            $url = 'https://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/index.php?route=' . $route;
        } else {
            $url = 'https://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/index.php?route=' . $route;
        }

关于php - Opencart 2.2.x ssl 用于所有请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36272499/

相关文章:

php - HMVC 架构可以用来做什么?

php - 关联表是否需要 Yii 框架中的模型?

php - Mysql 变量 max_allowed_pa​​cket 和查询的最大大小

php - .htaccess RewriteRule 不工作,加载 <name>.php 而不是 index.php?page=<name>

node.js - 将我的 SSL key 和证书文件传递给 Socket.IO 是否安全?

php - Sodium 未在 XAMPP PHP 7.2 上加载

apache - 通过 puppet 启用 .htaccess 文件

php - 通过 .htaccess 更改 PHP 中的 URL

linux - 确定 HTTPS apache 连接使用的密码强度

ssl - 证书验证是使用 memcmp 还是 Strcmp 的 SSL 握手?