我有一个非常简单的问题,出于某种原因我无法弄清楚,并且搜索了几个小时也没有帮助。使用 .htaccess 文件,如何将 /login.php
和 /index.php
重定向到 https,然后将任何其他页面重定向到 http?我目前使用此代码重定向到 https,但它会重定向每个页面:
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*) https://www.ruxim.com/$1 [R]
非常感谢。
最佳答案
%{SERVER_PORT}
变量取决于 UseCanonicalPhysicalPort在你的配置中。如果未设置,则您可能无法匹配该变量,使用 %{HTTPS}
更容易。
RewriteCond %{HTTPS} off
RewriteRule ^/?(login|index)\.php https://www.ruxim.com%{REQUEST_URI} [L,R]
RewriteCond %{HTTPS} on
RewriteRule !^/?(login|index)\.php http://www.ruxim.com%{REQUEST_URI} [L,R]
如果您不需要重定向到非 https,则不需要第二条规则。
关于.htaccess - 将选择的页面重定向到 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16071381/