我发现此代码将所有HTTP请求重定向到HTTPS。
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://my-domain.com/$1 [R,L]
在本地工作正常,但在现场导致浏览器错误 - “此页面未正确重定向。”
我也遇到了与此代码相同的问题:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
任何人都知道我做错了什么?顺便说一下,这是一个CodeIgniter网站。
[编辑 - 整个文件(减去尝试强制https)]
RewriteEngine on
#favour naked domain over www
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]
#imgs from Desyn
RewriteRule ^vstk_file\/([^\/]+)/([^\/]+)/(.+) vstk_file.php?store=$1&item=$2&file=$3
#ditch CI index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#route CSS files through PHP proxy to insert colour vars
RewriteRule (subj-(\w{11})\/)?([^\/]+)\.css$ assets/css/proxy.php?file=$3&subj-id=$2