目标是让网站的每个页面 (减去一个文件夹) redirect到https 。 我发现以下不这样做。 一个文件夹包含一个子域。 我们称之为mahogany.com。
编辑:修改规则
RewriteEngine On RewriteBase / RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^www.site1\.mobi [NC,OR] RewriteCond %{HTTP_HOST} ^site1\.mobi [NC,OR] RewriteCond %{HTTP_HOST} !^mahogany\.com [NC] RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
如果有人在浏览器中inputsite1.mobi或www.site1.mobi ,在文件根目录htaccess中的apache将不会redirect。
上面有什么问题? 是mahogany.com需要排除它吗?
RewriteCond的默认逻辑运算符是“and”; HTTP_HOST不能是这两个,所以条件永远不会被满足。
尝试这个:
RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^www\.site1\.mobi$ [NC,OR] RewriteCond %{HTTP_HOST} ^site1\.mobi$ [NC] RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
另外,你提到了一个目录exception,但我没有看到一个在那里。 您可以添加一个额外的RewriteCond或通过更改您的RewriteRule条件:
RewriteRule ^excepted/location/.* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]