.htaccess rewrite rule for forcefully redirect https to http

后端 未结 2 678
猫巷女王i
猫巷女王i 2021-01-23 12:39

I have a primary domain https://www.domain.com or https://domain.com and a wildcard DNS like https://domain.com/index.php?name=abcd redire

2条回答
  •  再見小時候
    2021-01-23 13:15

    You already have the rule for rewriting to https, the only thing left is excluding login.php

    RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain\.com)$
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} !^/login\.php$
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
    

    If login.php is requested with https, rewrite it to http

    RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain\.com)$
    RewriteCond %{HTTPS} on
    RewriteRule ^login.php$ http://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
    

    Finally, a minor hint: never test with 301 enabled, see this answer Tips for debugging .htaccess rewrite rules for details.

提交回复
热议问题