阿帕奇:%25 URL(400错误的请求) [英] Apache: %25 in url (400 Bad Request)

查看:406
本文介绍了阿帕奇:%25 URL(400错误的请求)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下内容的网址:

I have a url containing the following:

/somepath/morestuff/ohno%25foobar

由于某种原因Apache是​​报告一个400错误的请求(它有什么做的25%)。我使用了mod_rewrite重写路径指向我的codeigniter实例,但它甚至没有获得到codeigniter,它只是默认的Apache的错误。

For some reason apache is reporting a 400 bad request (it has something to do with the %25). I am using mod_rewrite to rewrite the path to point to my codeigniter instance but it's not even getting to codeigniter, it's just the default apache error.

任何想法?

推荐答案

我怀疑你使用 PATH_INFO 来处理你的codeIgniter请求。因此,你的的.htaccess 文件包含的规则集,类似于这样:

I suspect that you're using PATH_INFO to handle your CodeIgniter requests. Consequently, your .htaccess file contains a rule set that looks similar to this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php/$0 [L]

的mod_rewrite 测试您的网址,他们已经去coded到它们的自然字符格式,所以在这种情况下,%25 已经变成了。当应用了此规则,反向引用实际上包含文字文本 somepath / morestuff /大野%foobar的,这是的的重新连接$ C $默认情况下,CD。阿帕奇不知道这是什么在你的请求路径是做给 /index.php/somepath/morestuff/ohno%foobar 和扼流圈,给出这样的错误。

When mod_rewrite tests your URLs, they have already been decoded to their natural character format, so in this case %25 has become just %. When you apply this rule, the backreference actually contains the literal text somepath/morestuff/ohno%foobar, which is not re-encoded by default. Apache has no idea what that % is doing in your request path to /index.php/somepath/morestuff/ohno%foobar and chokes, giving you that error.

如果你正在运行的Apache 2.2,的mod_rewrite 添加 B 标记用于此目的,让您自动逃避改写为您的网址后向引用。将它添加到您当前的标志列表应该解决这个问题在这种情况下:

If you're running Apache 2.2, mod_rewrite added the B flag for this purpose, allowing you to automatically escape backreferences rewritten to your URL. Adding it to your current flag list should fix the problem in that case:

RewriteRule ^.*$ index.php/$0 [B,L]

另外还有一个逃跑 RewriteMap指令 这可作为的mod_rewrite 的内部地图,可惜这地图有在服务器或虚拟服务器配置级别启用,因此,如果您正运行在共享主机您的网站可能无法使用。它做同样的事情,但更多的是故意的。

There's also an escape RewriteMap that's available as an internal map in previous Apache versions of mod_rewrite, but unfortunately this map has to be enabled at the server or virtual server configuration level, so may not be available if you're running your site on shared hosting. It does the same thing, though a bit more deliberately.

在你的服务器/虚拟服务器的配置:

In your server/virtual server configuration:

RewriteMap escape int:escape

然后,只要你定义的规则:

Then, wherever you define your rules:

RewriteRule ^.*$ index.php/${escape:$0} [L]

请记住,codeIgniter并不需要使用 PATH_INFO 来获得请求的信息,并使用 REQUEST_URI 如果你不使用的mod_rewrite 做任何其他的转换(并会完全避免这个头痛)是完全可以接受的在这里。我认为,在默认情况下codeIgniter设置为获得 AUTO请求(假设我没有得到我的框架混合起来),所以根本就没有重写请求与路径信息URL将足以做出的改变。

Keep in mind that CodeIgniter doesn't need to use PATH_INFO to get the request information, and using REQUEST_URI is perfectly acceptable here if you aren't using mod_rewrite to do any other transformations (and would avoid this headache altogether). I think by default CodeIgniter is set to get the request from AUTO (assuming I haven't gotten my frameworks mixed up), so simply not rewriting the request to the URL with path info would be enough to make that change.

这篇关于阿帕奇:%25 URL(400错误的请求)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆