问题描述
我到处搜索这个答案,但发布的答案不适合我的具体情况,因为它给了我 404 错误,我不知道为什么.
I have searched everywhere for this answer, and the answers that have been posted do not fit my specific situation as it gives me 404 errors, and I'm not sure why.
我正在尝试重写:/c.php?url=http://www.example.com
进入这个:/c/http://www.example.com
现在我的 mod_rewrite 中有这个:
Right now I have this in my mod_rewrite:
RewriteEngine on
RewriteRule ^c/(.*)(/)?$ /c.php?url=$1
但是当它重写我试图发送到 PHP 脚本的 url 时,它会写http:/example.com
",用一个斜杠而不是双斜杠.
But when it rewrites the url that I am trying to send into the PHP script, it writes "http:/example.com
", with one slash instead of the double slash.
我已经看到很多关于 THE_REQUEST 规则的帖子,但是当我尝试将它们应用到我的 htaccess 文件时,它们失败了.我不确定出了什么问题,任何帮助将不胜感激.
I've seen a lot of things posted about this involving the THE_REQUEST rule, but when I try to apply them to my htaccess file, they fail. I am not sure what is wrong, any help would be much appreciated.
推荐答案
Apache 删除了路径中的多个斜线.正如您已经提到的,您可以通过检查 THE_REQUEST 中的请求行来解决这个问题:
Apache removes multiple slashes inside the path. And as you’re already mentioned, you can solve this by inspecting the request line in THE_REQUEST:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /c/([^?\ ]+)/?
RewriteRule ^c/ /c.php?url=%1
这篇关于在 mod_rewrite 中保留双斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!