htaccess 从 URL 中转义百分比 (%)

发布于 2024-09-28 07:41:41 字数 698 浏览 0 评论 0原文

URL 中包含百分号,会向浏览器返回错误请求(错误 400)。我有一个带有百分号(%)的文件名,驻留在服务器上。

原始文件名:

204153_20090605_Aluminiumacetotartraat_DCB_oordruppels_1,2%.pdf

单击下载链接后浏览器中的 URL:

http://www.example.com/204153_20090605_Aluminiumacetotartraat_DCB_oordruppels_1%2C2%25.pdf

这将返回 400 错误并显示“错误请求”。我使用的是Kohana 3。

现有的.htaccess文件内容如下:

RewriteEngine On

RewriteBase /

<Files .*>
Order Deny,Allow
Deny From All
</Files>

RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT] 

Having percent sign inside URL, returns bad request (error 400) to the browser. I have a filename that have percent (%) sign, resides at server.

Original File name:

204153_20090605_Aluminiumacetotartraat_DCB_oordruppels_1,2%.pdf

URL in browser after clicking on download link:

http://www.example.com/204153_20090605_Aluminiumacetotartraat_DCB_oordruppels_1%2C2%25.pdf

This returns 400 error with "bad request". I am using Kohana 3.

Existing .htaccess file contents are as follows:

RewriteEngine On

RewriteBase /

<Files .*>
Order Deny,Allow
Deny From All
</Files>

RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php/$0 [PT] 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魄砕の薆 2024-10-05 07:41:41

尝试使用 B 标志 以确保 %25< /code> 未通过 mod_rewrite 转义为 %,当插入回目标路径时,会重新转义回 %25

RewriteRule .* index.php/$0 [PTB]

Try the B flag to ensure the %25, unescaped to % by mod_rewrite, is re-escaped back to %25 when inserted back into the target path.

RewriteRule .* index.php/$0 [PTB]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文