【发布时间】:2017-01-02 01:58:44
【问题描述】:
好的,我发现我可以通过更改 .htaccess 文件中的内容来强制用户使用 SSL:
RewriteEngine On
RewriteBase /
# Force SSL
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Deny Access to all .htaccess
<Files .htaccess>
order allow,deny
deny from all
</Files>
我不太擅长编写 .htaccess 文件,所以我很可能从互联网上复制粘贴它。
我的问题是,是否可以始终强制使用 ssl,但有一个例外(当有人访问具有特定 url 参数的 http 站点时)。
示例 1:
http://example.com/test?name=John
被重定向到
https://example.com/test?name=John
示例 2:
http://example.com/test?name=John&nossl=1
不会被重定向到
https://example.com/test?name=John&nossl=1
是否可以在 htaccess 中编写,或者我是否需要在每个执行此操作的页面中包含一个 php 文件?
【问题讨论】: