[英]Redirect certain pages from http to https; redirect rest of site to www
[英]Redirect https to http for certain pages
除了登录和注册页面外,我想将https请求重定向到http。
因此,https:// example.com将重定向到http:// example.com,但是example.com/user/login应始终重定向到https://example.com/user/login 。
如何在.htaccess文件中执行此操作?
您可以使用mod_rewrite中的%{HTTPS}
变量来检测当前请求是否使用https。 这是on
还是off
。 请注意,您想要的重定向将不会具有发布请求的预期行为,因为重定向的URL将始终使用get来请求,而没有发布主体。
RewriteEngine on
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/user/(login|register)$
RewriteRule ^(.*)$ http://example.com/$1 [R,L]
RewriteCond %{HTTPS} =off
RewriteRule ^user/(login|register)$ https://example.com/user/$1 [R,L]
测试重定向工作按预期方式后,将R
标志更改为R=301
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.