2014-04-25 28 views
1

我在我的基本文件夾.htaccess文件中有規則。該規則會自動將http://重定向到https://。但是,對於一個特定的文件夾或URL我需要通過http訪問://將.htaccess規則禁用到特定目錄

重寫規則^(。*)$ HTTPS:/%{HTTP_HOST}%{REQUEST_URI} [L,R = 301]

對於例如我的網站會像https://開頭<> /功率/ A/1

但我需要不HTTPS訪問某些網址://

預計http://localhost/admin/rest_api/api_methods/

回答

0
RewriteEngine on 
RewriteBase/

RewriteRule ^$ app/webroot/ [L] 
RewriteRule (.*) app/webroot/$1 [L] 

# Turn SSL on for /user/login 
RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} !^/admin/rest_api 
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] 

# Turn SSL off everything but /user/login 
RewriteCond %{HTTPS} on 
RewriteCond %{REQUEST_URI} ^/admin/rest_api 
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L] 
1

你需要實現一個「例外規則「以的條件形式出現:

RewriteEngine on 
RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} !^/webservices/access 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
+0

編輯:只是意識到到目前爲止所顯示的建議會創建一個無止境的重寫循環。因此,當請求已經使用https時,您必須添加_a second_條件以防止重寫。我調整了上面的建議。 – arkascha

+0

我已將上述更改添加到我的.htaccess文件中。但它不起作用。 – Senthil

+0

「它不工作」在這裏沒有幫助。那是什麼意思?什麼都沒有發生?你得到一個錯誤?重寫的目標是一個錯誤的網址?宇宙爆炸了? – arkascha

0

這應該工作:

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/webservices/access 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

它將一切,但/webservices/access文件夾(或類似/webservices/access/login.php該文件夾中的任何其他鏈接)重定向到https

+0

以上更改無效。當我訪問URL http:// localhost/webservice/access時,它重定向到https – Senthil