.htaccess HTTPS重定向除了一页laravel

时间:2014-10-02 18:44:18

标签: regex apache .htaccess mod-rewrite laravel

我想将所有HTTPS请求重定向到HTTP,但包含此字符串的网址除外: " /帐户/购买溢价"

这是我的.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(错误 - 此处不需要重定向)

我找不到任何阻止重定向/ buy-premium页面的解决方案 请帮忙

1 个答案:

答案 0 :(得分: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]
相关问题