【问题标题】:htaccess to escape percent (%) from URLhtaccess 从 URL 中转义百分比 (%)
【发布时间】:2010-10-22 12:24:06
【问题描述】:

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

原始文件名:

204153_20090605_Aluminiumacetotartraat_DCB_oordruppels_1,2%.pdf

点击下载链接后浏览器中的网址:

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] 

【问题讨论】:

  • 我宁愿尝试修改文件名并删除%,

标签: .htaccess kohana-3


【解决方案1】:

尝试B flag 以确保%25(通过 mod_rewrite 未转义为 %)在插入回目标路径时重新转义回 %25

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

【讨论】:

  • 你忘记了[PT,B]中的逗号。
  • 感谢 @Gumbo 错误消失了,但它返回 500 错误,因为它无法将 %25 解析为 %。在访问日志中我得到了---127.0.0.1 - - [22/Oct/2010:18:29:42 +0530] "GET /204153_20090605_Aluminiumacetotartraat_DCB_oordruppels_1,2%25.pdf HTTP/1.1" 500 22514 "-" "Mozilla/ 5.0(Windows;U;Windows NT 5.1;en-US;rv:1.9.2.11)Gecko/20101012 Firefox/3.6.11"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-08
  • 2023-03-23
  • 2017-04-30
  • 2015-05-26
  • 1970-01-01
相关资源
最近更新 更多