我们使用Apache mod_rewrite控制是否通过http或https提供了一个页面。以下是站点根目录.htaccess文件的示例代码段:
# Redirect most reqests for https to http
RewriteRule ^https://www.example.com(.*) http://www.example.com$1 [R=301,NC]
# Allow some URIs to be https if requested
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^/images/(.*)$
RewriteCond %{REQUEST_URI} !^/scripts/(.*)$
RewriteCond %{REQUEST_URI} !^/styles/(.*)$
RewriteCond %{REQUEST_URI} !^/store(.*)$
RewriteCond %{REQUEST_URI} !^/login.htm$
RewriteRule ^(.*) http://www.example.com/$1 [L,R]
# Force some URIs to be https only
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^store(.*) https://www.example.com/store$1 [L,R]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^FormSanityKey.htm https://www.example.com/login$1 [L,R]
阅读全文: