2013-10-24 15 views
1

我用下面的.htaccess文件中的某些網頁重定向到https://笨的.htaccess用於SSL文件插入的index.php

RewriteEngine on 

RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} (sale|success|cancel) 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301] 

RewriteCond %{HTTPS} on 
RewriteCond %{REQUEST_URI} !(static|sale|success|cancel) 
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301] 

RewriteCond $1 !^(index\.php|resources|robots\.txt|static) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

這工作,除了當你去到被重寫頁面https://它也在URL中插入index.php。一切工作正常,但我希望index.php不被插入。有任何想法嗎?

謝謝。

回答

3

您錯過了L標誌。

您可以使用此代碼:

RewriteEngine on 

RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} (sale|success|cancel) [NC] 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

RewriteCond %{HTTPS} on 
RewriteCond %{REQUEST_URI} !(static|sale|success|cancel) [NC] 
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

RewriteCond $1 !^(index\.php|resources|robots\.txt|static) [NC] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
+0

謝謝,雖然沒有解決問題。 – GluePear

+0

在其他瀏覽器中測試以避免301緩存問題。 – anubhava

+0

是的,你是對的。非常感謝anubhava。 – GluePear

0
<Directory "/home/test"> 
    Require all granted 
    ***AllowOverride All*** 
    SSLOptions +StdEnvVars 
</Directory> 

在你的Apache配置中添加有 「AllowOverride全部」 後,它會正常工作。

問候。