TIP: Apache rewrite rules forgetting stuff

Tags: 

On a side project I'm working on they're using Apache mod_rewrite rules to turn ugly page addresses into pretty ones, e.g.:

RewriteRule widget-(.*)\.htm$ widget.php?id=$1

Nice goal and in general it works well. There was a problem, though, when they started doing this the SAJAX AJAX fancy stuff I wrote stopped working. A few thousand hair and some time later I worked out that one very simple keyword was missing from the rewrite rules, the %{QUERY_STRING} keyword to retain all of the extra fields passed in by SAJAX, e.g.:

RewriteRule widget-(.*)\.htm$ widget.php?id=$1&%{QUERY_STRING}

Also, note the extra ampersand in there before the keyword, you need this to separate the extra values from the one you're passing in from the widget-somat.htm address. Et voila!

How to reply

Care to add your own 2 cents? Let me know via Twitter or my contact page.