首页 > 解决方案 > Apache 2.4 如何仅重定向精确的 php 文件 - 但不是正常查询

问题描述

在我看来这很简单,但我仍然没有找到答案。

在 Apache 2.4 下,我需要将所有请求重定向到 http://example.com/data/request.phphttp://example.com/info.html 这很简单

RedirectMatch .*/request.php http://example.com/info.html

但我需要保持所有正常查询不变(如下所示)

http://example.com/data/request.php?id=26561

但使用 RedirectMatch 规则,所有正常查询也会重定向到

http://example.com/info.html?id=26561

感谢您尝试任何想法,

标签: apacheredirect

解决方案


谢谢上面@Capsule的提示-可能有人需要针对我的示例的确切答案

为了正确的重定向,我们必须使用

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?request.php$ http://example.com/info.html? [L,R]

它只重定向确切的

http://example.com/data/request.php

但留下完整的查询,如

http://example.com/data/request.php?id=26561

推荐阅读