MOD-重写正则表达式不工作的Apache重写、工作、正则表达式、MOD

2023-09-02 11:27:53 作者:无敌小萝莉

我试图让下面的工作:

当用户使用搜索框,获取发送用户 www.example.com/search/?s=Query+String

When a user uses a search box, the get sends the user to www.example.com/search/?s=Query+String

,发送GET请求是没有问题的,但是通过重写规则是抓住它。我不知道我的正则表达式是正确的在这种情况下。

Sending the GET request is not a problem, however, grabbing it via a RewriteRule is. I'm not sure my REGEX is proper in this case.

RewriteRule ^search/?s=(.*[^/])$ search.php?s=$1 [NC,L]

什么需要发生的是, /搜索/?S =查询+字符串查询字符串的一部分,必须取自该网址发送到的search.php?S =查询+字符串通过重写规则

What needs to happen is that the /search/?s=Query+String Query string part has to be taken from that url and sent over to search.php?s=Query+String via the Rewrite Rule

推荐答案

从请求查询字符串存储在变量%{QUERY_STRING} 。规则使用%{REQUEST_URI} 。只需使用 QSA 标记:

Query string from request is stored in variable %{QUERY_STRING}. Rules use %{REQUEST_URI}. Just use QSA flag:

RewriteRule ^search/?$ search.php [NC,L,QSA]

测试这里。