0

我发现了很多这样的问题并尝试了几乎所有但失败了。我最新的代码是:

RewriteCond %{HTTPS} !^on$
RewriteCond %{REQUEST_URI} (/page_1|/page_2|/page_3|/page_3)$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

我只想将这些页面的 http 重定向到 https (page_1 - page_4)

最初它似乎是有效的,但是一旦我使用https到达 page_1 并单击不应该是https的任何其他(比如说page_my_http_1 )链接,它也会重定向到该页面的 https (page_my_http_1)。

我也试过:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (auth|register|secure)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(auth|register|secure)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301]  

或者如果 SSL 证书未在浏览器上激活,有什么方法可以向用户显示自定义消息?

实际上,当浏览器显示默认警告消息时,许多非技术用户都会感到震惊。

4

1 回答 1

0

我只是稍微改变了你的例子,但基本上它只是工作

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/(?:auth|register|secure)$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/(?:auth|register|secure)$
RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R]

我添加了^,$/, 因为否则类似nosecureor的请求authority也会被重定向到 HTTPS。

永远不要在启用的情况下进行测试,有关详细信息301,请参阅此答案提示调试 .htaccess 重写规则

于 2013-03-07T13:38:57.077 回答