mod_rewrite 不使用编码的 URL 进行重写
我目前正在使用一个简单的路由器(在index.php 文件中)开发一个PHP 后端。 现在我有一个对路由的 REST 调用,包含像这样的 url 编码的 url:
https://api.example.com/{encoded url}/information
示例:https://api.example.com/https%3A%2F%2Fwww.example.com%2Fcategory%2Fexample -slug/information
我的 .htaccess 文件,应该将所有调用重定向到 index.php 文件:
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
RewriteRule !^index\.php$ index.php [L]
现在的问题是,当访问这样的路由时,Apache 服务器显示我默认 404 页面,意味着请求未重定向到 index.php 文件。似乎编码的 /
(%2F
) 是问题所在,但我不知道如何解决这个问题。
I am currently developing a PHP-backend using a simple router (in the index.php file).
Now I have a REST-Call to a route, containing a url-encoded url like this:
https://api.example.com/{encoded url}/information
Example: https://api.example.com/https%3A%2F%2Fwww.example.com%2Fcategory%2Fexample-slug/information
My .htaccess
-file, that should redirect all calls to the index.php file:
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
RewriteRule !^index\.php$ index.php [L]
Now the problem is, that when accessing such a route, the Apache-Server shows me the default 404 page, meaning the request was not redirected to the index.php file. It seems like the encoded /
(%2F
) are the problem, but I don't know how to fix this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是 Apache 的编码斜杠指令,根据 @CBroe 的评论:
https://httpd.apache.org/docs/2.4/mod/ core.html#allowencodedslashes
Solution is the encoded slashes directive of Apache, as per @CBroe's comment:
https://httpd.apache.org/docs/2.4/mod/core.html#allowencodedslashes