MOD-重写正则表达式不工作的Apache [英] Mod-Rewrite REGEX not working Apache
问题描述
我试图让下面的工作:
当用户使用搜索框,获取发送用户 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]
测试这里。
这篇关于MOD-重写正则表达式不工作的Apache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!