【问题标题】:.htaccess HTTPS redirect except one page laravel.htaccess HTTPS 重定向,除了一页 laravel
【发布时间】:2014-11-27 19:59:17
【问题描述】:

我想将所有 HTTPS 请求重定向到 HTTP,但包含此字符串的 url 除外: "/account/buy-premium"

这是我的 .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 页面的重定向
请帮忙

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite laravel


    【解决方案1】:

    您将需要使用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]
    

    【讨论】:

    • 太棒了!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    • 2020-10-10
    • 2014-12-13
    • 2014-03-26
    • 2015-09-21
    • 1970-01-01
    • 2019-06-27
    相关资源
    最近更新 更多