Mod-Rewrite REGEX not working Apache

大兔子大兔子 提交于 2019-12-24 12:34:09

问题


I am trying to get the following working:

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

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]

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


回答1:


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]

Tested here.



来源:https://stackoverflow.com/questions/15411898/mod-rewrite-regex-not-working-apache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!