.htaccess:除了某些页面外,从http重定向到https?

时间:2017-04-06 07:58:22

标签: .htaccess

我想从http tp https重定向我的所有网站,但在某些页面上除外:

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

ex:要排除的页面:

  

/ home / user / info / mydata /ajax.php

1 个答案:

答案 0 :(得分:2)

添加另一个RewriteCond指令:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/(home|user|info|myta|ajax\.php)
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

或单一规则:

RewriteCond %{HTTPS} off
RewriteRule ^/?(?!home|user|info|myta|ajax\.php) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]