我使用下面的重写规则将2个php页面redirect到https(以保护用户数据),但是每当我点击这些php页面上的任何链接时,它们都会使用https进行redirect,页面无法正确显示。
底部的规则是为了将任何其他页面redirect回http,但它们不起作用。 任何意见将不胜感激!
RewriteEngine on RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} ^/securepage1.php$ [NC] RewriteRule ^(.*)$ https://www.example.com$1 [L,R=301] RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} ^/securepage2.php$ [NC] RewriteRule ^(.*)$ https://www.example.com$1 [L,R=301] RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !^/securepage1.php$ [NC] RewriteCond %{REQUEST_URI} !^/securepage2.php$ [NC] RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
尝试启用日志logging以清楚哪些步骤失败:
RewriteLog /path/to/log RewriteLogLevel 2
您可以使用大于2的值作为日志级别,但请记住,这将影响您的服务器的性能,因此请小心在繁重的生产实例上运行此值。
现在,为了一些安全的想法。 如果你足够担心保护特定页面(而不是其他)的数据,那么最好的问题是:值得在你的网站上只有2页值得信赖? 如果我导航到http://example.com并被中间人攻击(MIM)攻击,您的用户是否确实在乎https://example.com/securepage1.php在MIM攻击时是否安全去http://badpage.com/securepage1.php ? 换句话说,如果这是一个交互式网站的一部分,保护这两个安全页面什么都不做,因为用户从一开始就不能真正信任该网站。