Searched, Designed, Developed. I-COM Blog

What is the opposite of the htacess [QSA] flag?

By Darryl Browne in Web Development on Wednesday, August 6, 2008 @ 13:26

Normal procedure for using mod_rewrite is to translate friendly url's into something your underlying server technology can interpret. Something like:

RewriteRule ^blog-blog-title-(14)\.html$ blog.php?id=$1 [L]

But recently I had to do the process in reverse which seemed straightforward:

RewriteCond %{QUERY_STRING} id=14
RewriteRule ^blog\.php$ blog-blog-title-14.html [L]

But when the rule was invoked, this happened:

blog-blog-title-14.html?id=14

mod_rewrite was attaching the query string automatically, assuming this was the behaviour I was looking for. After spending a long time Googling various things to try and find an answer (and finding precious little to help me, even on webmaster help forums such as ExpertsExchange) I came up with nothing. It's almost as if nobody had attempted this before.

After some intensive really obscure searches I managed to find the not so straightforward solution which I could not find anywhere in the Apache docs. The solution is to stick this string (I have no idea what it does or why it works, but it does) after your mapped url:

${pages:%1¦NULL}?

Example:

RewriteCond %{QUERY_STRING} id=14
RewriteRule ^blog\.php$ blog-blog-title-14.html${pages:%1¦NULL}? [L]

This little string is nowhere near publicised enough nor is it easily searchable on Google, so I hope that I can help to spread the word by mentioning it here.

jo wrote:

May 21, 2009 - 12:16
add ? to RewriteRule ^blog\\.php$ blog-blog-title-14.html [L]

like

RewriteRule ^blog\\.php$ blog-blog-title-14.html? [L]

i think

Peter wrote:

Oct 19, 2009 - 09:16
And the day is saved, thanks to Darryl. Thank you!

Berion wrote:

Mar 01, 2010 - 11:05
It works!! Really, Thank you to share this very important information!!! (^o^)b

Add Comment

Emails are used strictly for administration purposes. Your email address will not appear on the site.

CAPTCHA