opencart htaccess太多重定向

时间:2017-06-25 12:46:04

标签: apache .htaccess redirect mod-rewrite

我想将http设置为https。但是,当我访问https时,会导致重定向太多。

以下是我的规则: -

     .then(response => response.json() as Project[])

在我的cPanel网站上,相同的编码工作正常。但是,当我移动到另一台服务器(VPS)时,它只是不起作用。

当我通过RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$ RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L] RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L] #NEW REWRITE RULES RewriteRule ^contact/?$ index.php?route=information/contact [L] #Contact Page #END NEW REWRITE RULES 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] 访问时,它会重定向到http://www.example.com,但是下一个错误将会重定向太多。

如果我发表评论

https://www.example.com

然后它会在 HTTPS 中正常工作,完全不知道......

我无法理解它为什么遇到无限循环条件。 http://htaccess.mwl.be?share=e7301d40-f5c3-5476-aa44-de304a066bf6

Apache版本:2.4.23-0ubuntu1

PHP:7.0.20

1 个答案:

答案 0 :(得分:1)

将您的第一条规则更改为:

RewriteCond %{REQUEST_SCHEME} =http 
RewriteCond %{THE_REQUEST} !/[0-9]+\..+\.cpaneldcv [NC]
RewriteCond %{THE_REQUEST} !/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)? [NC]
RewriteCond %{THE_REQUEST} !/\.well-known/acme-challenge/[\w-]+ [NC]
RewriteRule ^ https://%{HTTP_HOST%{REQUEST_URI} [R,L,NE]

%{REQUEST_URI}替换为%{THE_REQUEST},因为REQUEST_URI在您上一条规则中更改为index.php,从而再次触发您的第一条规则。

如果您正在使用代理,那么您还需要添加此条件:

RewriteCond %{HTTP:X-Forwarded-SSL} =off