2014-03-25 25 views
3

我試過對這個問題實施了一些建議的解決方案,但無法獲得任何工作。htaccess https在父級但http在子目錄中

我使用2個.htaccess文件,一個在我的根目錄下,其內容如下:

RewriteEngine on 
RewriteBase/
RewriteRule ^(webservice|api) - [L] 
RewriteCond %{HTTPS} off 
RewriteRule (.*) https://www.domain.com%{REQUEST_URI} [R=301,L] 

這重定向所有到主網站通過HTTPS,我需要。

但是,在一個子目錄中,我想禁用重新路由並強制所有通過http訪問該目錄的請求。在/ Web服務/休息.htaccess文件/讀取:

RewriteEngine On 
RewriteBase /webservice/rest/ 
RewriteCond %{HTTPS} on 
RewriteRule (.*) http://www.domain.com/webservice/rest/%{REQUEST_URI} [R=301,L] 
RewriteRule ^testingPost/?$ testingPost.php [NC] 
RewriteRule ^([a-zA-Z0-9\_\-]+)/?(\?([a-zA-Z0-9\_\-\=\?\&]))?$ otherfiledirect.php?method=$1&params=$2 [NC] 

有幾個重定向發生,但第3和第2 htaccess的4號線似乎沒有被做任何事情 - 任何人都可以看到什麼我做錯了,如何在主站點上保留https,但強制http/webservice/rest /下的任何URL。

乾杯

回答

3

的問題是在服務器的SSL配置文件。允許有待在端口443安全虛擬主機下設置爲全部覆蓋變化之後,在根htaccess文件下面的代碼讓我強制HTTPS在整個網站除了一個特定的文件夾:

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

所以對http的任何請求都會轉到https。不過,我仍然需要明確地改變我的指定文件夾請求到https重定向到HTTP,所以添加了上述後下面的代碼:

RewriteCond %{HTTPS} on 
RewriteCond %{REQUEST_URI} /webservice  [NC] 
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

防彈。

0

/webservice/rest/.htaccess試試這個,並確保在新的瀏覽器測試:

RewriteEngine On 
RewriteBase /webservice/rest/ 

RewriteCond %{HTTPS} on 
RewriteRule^http://www.domain.com/%{REQUEST_URI} [R=301,L,NE] 

RewriteRule ^testingPost/?$ testingPost.php [L,NC] 

RewriteRule ^([\w-]+)/?(\?([\w-=?&]))?$ otherfiledirect.php?method=$1&params=$2 [L,NC] 
+0

謝謝anubhava - 雖然似乎沒有工作。也許這是與標誌有關 - 在根htaccess我有L後重寫規則^(webservice | api) - 似乎無法使任何工作,雖然 - 任何其他想法? – contool

+0

用於測試重命名root .htaccess和你用什麼URL測試? – anubhava

+0

我完全禁用了root htaccess,但是sub htaccess仍然沒有重定向到http。 – contool

相關問題