2017-02-13 40 views
0

訪問一個網址我有.htaccess重寫規則,我們的網站重定向到HTTPS的.htaccess允許或者通過HTTPS或HTTP

RewriteEngine on 
RewriteCond %{HTTPS} off 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

我需要留下一個網址打開工作HTTP和HTTPS( http://www.myhost.com/apihttps://www.myhost.com/api)。如何做我需要修改我上面的代碼如下規則

回答

1

嘗試,

RewriteEngine on 
RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} !^/support/registration_service 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

上述規則不包括URI /api被迫HTTPS,所以你可以使用www.myhost.com/api兩個方案。

+0

我得到'內部服務器錯誤'與該附加規則 –

+0

它有一個錯字,請嘗試編輯! –

+0

好的,現在錯誤消失了,但它仍然自動重定向到HTTPS。我的實際URL實際上是'http:// www.myhost.com/support/registration_service'而不是'api'。也許這與這有關...我已經改變了'RewriteCond%{REQUEST_URI}!^ api'到'RewriteCond%{REQUEST_URI}!^ support/registration_service' –