【发布时间】:2017-03-01 16:36:23
【问题描述】:
我正在尝试通过 .htaccess 强制使用 HTTPS,但我经常收到重定向过多的错误。
这是我的 .htaccess 文件:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^patrickwhitehouse.pw$ [NC]
RewriteRule ^(.*)$ http://patrickwhitehouse.pw/$1 [L,R=301]
#force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Options +MultiViews
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^&\ ]+).html
RewriteRule .* /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.html [L]
RedirectMatch ^/blogs$ http://www.patrickwhitehouse.pw/blog.html
【问题讨论】: