1

我有一个非常简单的问题,由于某种原因我无法弄清楚,而且数小时的搜索也没有帮助。使用 .htaccess 文件,如何仅重定向/login.php/index.phphttps,然后将任何其他页面重定向到 http?我目前使用此代码重定向到 https,但它重定向每个页面:

RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*) https://www.ruxim.com/$1 [R]  

非常感谢您。

4

3 回答 3

2

The %{SERVER_PORT} variable depends on the UseCanonicalPhysicalPort in your config. If it's not setup, then you may not be able to match against that variable, easier to use %{HTTPS} instead.

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]

If you don't need the redirect to non-https, then you don't need the second rule.

于 2013-04-17T22:48:21.900 回答
0

请应用以下条件以仅保护 /login.php 和 /index.php 页面。其他页面将在 HTTP 路径上工作(非安全页面)。

RewriteEngine On
RewriteBase /
# force https for /login.php and /index.php
RewriteCond %{HTTPS} =off
RewriteRule ^(index|login)\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# don't do anything for images/css/js (leave protocol as is)
RewriteRule \.(gif|jpe?g|png|css|js)$ - [NC,L]

# force http for all other URLs
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/(index|login)\.php$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
于 2013-04-22T09:03:44.310 回答
0

尝试这样的事情;

RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_FILENAME} =index.php [OR]
RewriteCond %{REQUEST_FILENAME} =login.php
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

我注意到 100% 肯定[OR]会在中间突然遵守。

于 2013-04-17T22:41:29.147 回答