mod_rewrite 不使用编码的 URL 进行重写

发布于 2025-01-16 08:02:14 字数 627 浏览 1 评论 0原文

我目前正在使用一个简单的路由器(在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野稚 2025-01-23 08:02:14

解决方案是 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文