我从这个网站获得了帮助,以获取.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)
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]
我尝试了一些不同的差异,没有任何工作。 :(
答案 0 :(得分:0)
我通过在我想要保护的目录中放置单独的.htaccess文件来解决它,包含:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}