【问题标题】:htaccess rewrite url to https and remove filenamehtaccess 将 url 重写为 https 并删除文件名
【发布时间】:2014-12-25 10:53:40
【问题描述】:

我正在使用 symfony2 框架,它为我使用 htaccess mod rewrite 删除的每个页面调用 app.php 文件,我正在尝试编写 htaccess 以将两个页面(带有动态 url)重定向到 https 和其余页面站点到常规 http,这就是我现在的立场:

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{HTTPS} !=on
    RewriteRule ^(payment|withdraw)(/|$)  https://%{HTTP_HOST}%{REQUEST_URI}  [R=301,L,QSA]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php/$1 [QSA,L]

    #RewriteCond %{HTTPS} =on
    #RewriteRule !^(payment|withdraw)(/|$)  http://%{HTTP_HOST}%{REQUEST_URI}  [R=301,L,QSA]

</IfModule>

这适用于将 https 添加到特定页面,但如果我添加注释掉的行以将其余页面重定向到常规 http,它会破坏第一部分,而不是 http://www.example.com/payment/item_1 变为 http://www.example.com/app.php/payment/item_1 而不是 https://www.example.com/payment/item_1

【问题讨论】:

    标签: apache .htaccess symfony mod-rewrite https


    【解决方案1】:

    重新排序您的规则,因为您必须在内部重写之前保留重定向规则:

    <IfModule mod_rewrite.c>
        RewriteEngine on
    
        RewriteCond %{HTTPS} off
        RewriteCond %{THE_REQUEST} /(payment|withdraw)[/\s]
        RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
    
        RewriteCond %{HTTPS} on
        RewriteCond %{THE_REQUEST} !/(payment|withdraw)[/\s]
        RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
    
        RewriteCond %{REQUEST_FILENAME} !-f    
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ app.php/$1 [L]
    
    </IfModule>
    

    【讨论】:

    • 感谢您的评论,但这段代码仍然存在同样的问题。
    • 检查另一个更新,虽然我相信你的问题是旧的浏览器缓存而不是规则。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-02
    • 2018-05-25
    • 1970-01-01
    • 2020-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多