2011-09-01 66 views
0

我得到的幫助從這個網站獲得運行代碼的.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) 
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

規則的login.php中並註冊? .php頁面。我還需要強制ssl用於兩個目錄,並確保它們在最後一條規則中被排除,或者如果僅添加到第一條規則,它們將被強制爲http。 – Jen

回答

0

我解決它通過將不同的.htaccess文件在我想保護的目錄,包含:

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
相關問題