.htaccess-如何使规则同时应用于特定页面和目录
我从该网站获得了帮助,以获取.htaccess的功能代码:.htaccess-如何使规则同时应用于特定页面和目录,.htaccess,.htaccess,我从该网站获得了帮助,以获取.htaccess的功能代码: # force https for /login.php and /register.php RewriteCond %{HTTPS} off RewriteRule ^(login|register)\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] # don't do anything for images/css/js (leave protocol as is) Rewri
# force https for /login.php and /register.php
RewriteCond %{HTTPS} off
RewriteRule ^(login|register)\.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 %{SCRIPT_FILENAME} !(login|register)\.php$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
但现在我意识到我还需要在这些规则中添加几个目录。如何做到这一点
为什么以下操作不起作用:
# force https
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} ^(securimage|ADM)/(.*)$
RewriteCond %{SCRIPT_FILENAME} ^(login|register)\.php$
RewriteRule .* 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 %{SCRIPT_FILENAME} !(securimage|ADM)/(.*)$
RewriteCond %{SCRIPT_FILENAME} !(login|register)\.php$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
我尝试了一些不同的变化,但没有任何效果 我通过将单独的.htaccess文件放在我想要保护的目录中解决了这个问题,其中包含:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
添加两个目录,其中包含login.php和register.php页面的规则。我还需要对两个目录强制使用ssl,并确保它们也被排除在最后一条规则中,否则,如果只将它们添加到第一条规则中,它们将被强制使用http。。。