mod_rewrite passing variables

人盡茶涼 提交于 2020-02-03 10:40:05

问题


I have the following mod_rewrite rule:

RewriteRule ^([^/.]+)/?$ search.php?action=procedure&procedureName=$1

This works fine in redirecting things like /blabla to /search.php?action=procedure&procedureName=blabla

The problem is that sometimes I want to pass a 'start' value (for pagination). For example, /blabla/?start=20.

Currently, it just ignores it. Printing out the $_REQUEST array doesn't show 'start'. I tried modifying the rule to:

RewriteRule ^([^/.]+)/\?start=([0-9]+)$ search.php?action=procedure&procedureName=$1&start=$2
RewriteRule ^([^/.]+)/?$ search.php?action=procedure&procedureName=$1

But it didn't do anything.

Any idea?

Thanks


回答1:


RewriteRule ^([^/.]+)/?$ search.php?action=procedure&procedureName=$1 [L,NC,QSA]

The QSA means query string append, and it'll append $_GET vars you pass. Otherwise, they are normally not added.




回答2:


RewriteRule applies to the path. You need to use RewriteCond to match the query string.

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule

Or to just pass the query string through, use %{QUERY_STRING}

RewriteRule ^([^/.]+)/?$ search.php?action=procedure&procedureName=$1&%{QUERY_STRING}



回答3:


Actually I think I found my answer:

RewriteRule ^([^/.]+)/?$ search.php?action=procedure&procedureName=$1 [QSA]

The QSA allows it to pass query strings. Right?



来源:https://stackoverflow.com/questions/1597794/mod-rewrite-passing-variables

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