![](/img/trans.png)
[英]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.