.htaccess: redirect from http to https except on some pages?

僤鯓⒐⒋嵵緔 提交于 2020-01-07 11:53:46

问题


I would like to redirect all my website from http tp https except on some pages:

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

ex: pages to be excluded :

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


回答1:


Add yet another RewriteCond directive:

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

or in a single rule:

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


来源:https://stackoverflow.com/questions/43249133/htaccess-redirect-from-http-to-https-except-on-some-pages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!