【问题标题】:%25 in being appended in htaccess redirected Url%25 被附加到 htaccess 重定向的 Url
【发布时间】:2017-05-12 08:40:47
【问题描述】:

我尝试将所有非 https url 重定向到 http,所以我在 .htaccess 中使用它

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [B,R,L]

但是当我从 url 中删除 https 进行测试时,它会重定向到 https 但它会转到 https://example.com/%25myfile.php

%25 被添加到 url 中并使得链接 NOT FOUND 。我在上面犯了一些错误吗?我按照Apache: %25 in url (400 Bad Request) 并添加了标志B,如上面的代码所示,但它不起作用。

谢谢。

【问题讨论】:

    标签: apache .htaccess http mod-rewrite https


    【解决方案1】:

    用这条规则改变你的规则:

    RewriteEngine On
    
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [NE,R=301,L]
    
    • NE 标志防止编码特殊字符。
    • %{REQUEST_URI} 使用与当前目录无关的原始 URI。

    确保在测试更改之前清除浏览器缓存。

    【讨论】:

    • 谢谢你,完成了这项工作:)
    猜你喜欢
    • 2010-12-15
    • 2012-02-16
    • 2018-10-10
    • 2020-02-19
    • 2023-04-03
    • 2015-04-24
    • 2014-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多