【发布时间】:2015-11-28 10:42:54
【问题描述】:
谁能告诉我如何在我的整个网站上强制使用 https,而不是在单个文件夹或 url 上。 目前我有这个代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^thatmysite\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://thatmysite.com/$1 [R,L]
但是,如果我在根 htaccess 中添加第二个代码以从 /thatsite.com/printing 文件夹中删除 https,我会得到一个重定向循环,因为我强制代码 http 到 https 而不是 https 到 http...
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{REQUEST_URI} ^\/(printing)
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTP:X-Forwarded-SSL} =on
RewriteCond %{REQUEST_URI} !^\/(printing)
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]
请问您知道解决方法吗?我一直在寻找整个互联网,找不到一个好的答案。
【问题讨论】:
标签: apache .htaccess mod-rewrite https