2014-10-02 154 views
2

我想重定向的URL以外的所有HTTPS請求HTTP包含此字符串: 「/帳號/買入溢價」的.htaccess HTTPS重定向laravel

這裏是我的.htaccess文件:

RewriteEngine On 
RewriteCond %{HTTPS} !=on 
RewriteCond %{REQUEST_URI} ^/account/buy-premium [NC] 
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L] 

RewriteCond %{HTTPS} on 
RewriteCond %{REQUEST_URI} !^/account/buy-premium [NC] 
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R,L] 

# Redirect Trailing Slashes... 
RewriteRule ^(.*)/$ /$1 [L,R=301] 

# Handle Front Controller... Default Laravel conf 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [L] 

https://開頭example.com/test-page被重定向到HTTP:// example.com/test-page(好)

https://example.com/account/buy-premium/991被重定向到http://example.com/index.php(壞的 - 在此不再重定向)

我無法找到任何解決方案,以防止重定向的/買保費頁
請幫

回答

4

您將需要使用THE_REQUEST而不是REQUEST_URI,因爲REQUEST_URI根據您最後的規則更改爲/index.php

RewriteEngine On 
RewriteCond %{HTTPS} !=on 
RewriteCond %{THE_REQUEST} \s/account/buy-premium [NC] 
RewriteRule^https://%{SERVER_NAME}%{REQUEST_URI} [R,L] 

RewriteCond %{HTTPS} on 
RewriteCond %{THE_REQUEST} !\s/account/buy-premium [NC] 
RewriteRule^http://%{SERVER_NAME}%{REQUEST_URI} [R,L] 

# Redirect Trailing Slashes... 
RewriteRule ^(.*)/$ /$1 [L,R=301] 

# Handle Front Controller... Default Laravel conf 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^index.php [L] 
+0

非常好!非常感謝你! – user3842742 2014-10-02 19:48:56

+0

不客氣,很高興它的工作。 – anubhava 2014-10-02 19:50:24