问题
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