url 编码的正斜杠破坏了我的 codeigniter 应用程序 [英] url encoded forward slashes breaking my codeigniter app
问题描述
我正在尝试创建一个像这样工作的 url 字符串:
i’m trying to create a url string that works like this:
/app/process/example.com/index.html
换句话说,
/app/process/$URL
然后我用
$this->uri->segment(3);
URL 中的正斜杠当然会成为访问 uri 段的问题,所以我将继续对 URL 部分进行 url 编码:
the forward slashes in the URL will of course be a problem accessing uri segments, so i’ll go ahead and url encode the URL portion:
/app/process/example.com%2Findex.html
...但现在我只收到一个 404 说...
.. but now I just get a 404 saying ...
Not Found
The requested URL /app/process/example.com/index.html was not found on this server.
看来我的正斜杠 url 编码破坏了 CI 的 URI 解析器.
it appears that my url encoding of forward slashes breaks CI’s URI parser.
我该怎么做才能解决这个问题?
what can i do to get around this problem?
推荐答案
我认为您收到的错误消息不是来自 codeigniter,而是来自您的 Web 服务器.
I think the error message you are getting is not from codeigniter but from your web server.
我使用 Apache2 复制了这个,甚至没有使用 CodeIgniter:我创建了一个文件 index.php,然后访问了 index.php/a/b/c
- 它工作正常.如果我随后尝试访问 index.php/a/b/c%2F
,我会收到来自 Apache 的 404.
I replicated this using Apache2 without even using CodeIgniter: I created a file index.php, and then accessed index.php/a/b/c
- it worked fine. If I then tried to access index.php/a/b/c%2F
I got a 404 from Apache.
我通过添加到我的 Apache 配置中解决了这个问题:
I solved it by adding to my Apache configuration:
AllowEncodedSlashes On
请参阅文档了解更多信息
完成此操作后,您可能需要在 codeigniter 中修改 $config['permitted_uri_chars']
如果它仍然无法正常工作 - 您可能会发现斜线被过滤掉
Once you've done this you might need to fiddle around with $config['permitted_uri_chars']
in codeigniter if it is still not working - you may find the slashes get filtered out
这篇关于url 编码的正斜杠破坏了我的 codeigniter 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!