【问题标题】:Redirect https to http using htaccess in opencart在opencart中使用htaccess将https重定向到http
【发布时间】:2015-03-18 07:15:51
【问题描述】:

我已经安装了 opencart 2.0.1.1,我需要将 https://www.domain.com 重定向到 http://www.domain.com。如何使用 htaccess 文件实现它。

我已在 htaccess 文件中尝试过此代码。但这不起作用。

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

我应该如何将 https URL 重定向到 http。我还在 opencart 中检查了 config.php 文件,它不包含任何 https URL。

opencart现有的htaccess文件包含如下代码

RewriteBase /
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]

但该文件不是 htaccess 文件。它只是一个名为 htaccess.txt 的文本文档。

提前致谢。

【问题讨论】:

  • 什么具体不起作用?
  • 当我运行 https url 时,它不会重定向到 http。
  • 应该可以。您确定您的服务器配置为允许 .htaccess 文件吗?你还有其他的 htaccess 文件在使用吗?
  • 是的,我允许 htaccess 文件工作。我尝试重定向 index.php 文件,它在这种情况下有效,但是当我重定向到 http 时它不起作用

标签: php .htaccess redirect opencart


【解决方案1】:

最后一个;)

你可以试试把这段代码,改成你的域名

在 config.php 和 admin/config.php 文件中将引用改为 https,替换为“http”。

define('HTTPS_SERVER', 'http S://www.example.com/');
define('HTTPS_IMAGE', 'http S://www.example.com/image/');

替换

define('HTTPS_SERVER', 'http://www.example.com/');
define('HTTPS_IMAGE', 'http://www.example.com/image/');

我的 htaccess 文件:

Options +FollowSymlinks

# Prevent Directoy listing 
Options -Indexes

# Prevent Direct Access to files
<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
 Order deny,allow
 Deny from all
</FilesMatch>

# SEO URL Settings
RewriteEngine On

RewriteCond %{HTTP_HOST} ^yourDomain.com
RewriteRule ^ http://yourDomain.com%{REQUEST_URI} [L,R=301]


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]

问候,

【讨论】:

    【解决方案2】:

    这是解决方案:

     RewriteCond %{HTTP_HOST} ^yourDomain.com
     RewriteRule ^ http://www.yourDomain.com%{REQUEST_URI} [L,R=301]
    

    或者,如果你喜欢不使用 www ,

     RewriteCond %{HTTP_HOST} ^yourDomain.com
     RewriteRule ^ http://yourDomain.com%{REQUEST_URI} [L,R=301]
    

    并且,在管理面板中:

    系统->设置->服务器-> ssl=否

    问候,

    【讨论】:

    • 这不起作用。管理面板中的 SSL 已关闭。我通过创建一个新的 htaccess 文件编写了这段代码。这是正确的方法吗?还是我应该在现有的 htaccess.txt 文件中的这段代码中编写这段代码?
    【解决方案3】:

    是的,好的 我以为你有一个“正确的”htaccess。请进行以下操作:

    创建一个新文件 .htaccess 或将 htaccess.txt 重命名为 .htaccess 。文件名中的“点”很重要。 “.htaccess”(我建议你重命名文件)

    先放那个文件 重写引擎开启

    RewriteEngine On 
    RewriteCond %{HTTP_HOST} ^yourDomain.com
    RewriteRule ^ http://www.yourDomain.com%{REQUEST_URI} [L,R=301]
    

    或者,如果您不喜欢使用 www ,

     RewriteEngine On
     RewriteCond %{HTTP_HOST} ^yourDomain.com
     RewriteRule ^ http://yourDomain.com%{REQUEST_URI} [L,R=301]
    

    并且,在管理面板中:

    系统->设置->服务器-> ssl= NO 系统->设置->服务器->网址搜索引擎优化->是

    请再试一次:) 问候,

    【讨论】:

    • 感谢您的回复。但是我再次怀疑如果我更改现有的 htaccess.txt 文件,那么其中已经存在的代码会怎样。由于我是 opencart 和 htaccess 文件的新手,请多多包涵
    【解决方案4】:

    将此代码添加到 .htaccess 文件中,它应该重定向到您在配置文件中的内容。

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteCond %{ENV:HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 2019-03-18
      • 2012-10-11
      • 2015-11-10
      • 2018-08-31
      • 2012-11-02
      • 1970-01-01
      • 2015-02-16
      • 2015-10-28
      • 2019-03-10
      相关资源
      最近更新 更多