2013-10-02 29 views
1

我使用此代碼mod_rewrite的重定向所有到https除了一個文件

RewriteCond %{HTTPS} off 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

重定向所有請求到HTTPS,這是好的。

現在我想同樣的事情,除了一個文件index810.php

當我寫這樣的

RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} !^ index810.php 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

我得到太多的重定向,任何建議。

預先感謝您

回答

5

一個解決方案是使用非重寫規則:

# do nothing for /index810.php 
RewriteRule ^index810\.php$ - [L] 
# else ... 
RewriteCond %{HTTPS} off 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} 

你的模式是錯誤的:

  • 之間存在^和index810空間.php
  • %{REQUEST_URI}是所有HTTP路徑(即,如果在文檔根目錄下,它將爲=/index810.php
+0

非常感謝julp我修改它一點,使它更一般的工作太棒了! RewriteRule ^。* index810 \ .php $ - [L] –

+0

爲了使它適用於/index810.php,而不是'^ index810 \ .php $',我認爲你應該使用'^/index810 \ .php $ ' – lucaferrario

+0

@lucaferrario:在目錄上下文中(即在.htaccess或''塊中),Apache刪除映射到RewriteRule目錄的URL路徑的一部分。 [文檔](http://httpd.apache.org/docs/2.4/en/mod/mod_rewrite.html#rewriterule)說:「[...]刪除的前綴總是以斜線結尾,表示匹配發生對於一個從不具有前導斜槓的字符串,因此,帶'^ /'的模式在每個目錄上下文中都不匹配**。[...]「。您的評論僅適用於RewriteRule不在目錄上下文中的情況(例如直接在VirtualHost中進行規則)。 – julp

0

接受的答案對我無效。然而,這確實如此:

RewriteCond %{THE_REQUEST} !/index810\.php [NC] 
RewriteCond %{HTTPS} off 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} 
相關問題