3

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

3 Answers 3

11
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}
1

Actually I think I found my answer:

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

The QSA allows it to pass query strings. Right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.