Cuelogic Blog Icon
Cuelogic Career Icon
Home > Blog > Product Development > Web > QueryString in .htaccess – Match Question Mark in rewrite rule

QueryString in .htaccess – Match Question Mark in rewrite rule

I am changing my development structure to have rewrite urls for fuse/action and I thought it’s cool if I represent all URLs like google ( http://www.google.co.in/search?hl=en&client=firefox-a)

so http://mysite.com?index.php?action=search&q=vikrant should look like
http://mysite.com/search?q=vikrant

for this purpose I have first tried a simple rule to match anything after “/”.

RewriteEngine On

RewriteRule ^(.*)$ index.php?action=$1 [L]

but when I print GET variables then it s only giving me the part before “?” (that was strange)

Then after googling a bit I just got the hint that Mod Rewrite do not matches string after “?” because it’s treating it as %{QUERYSTRING} , hence I have created following rule to achieve the result which is running perfect for me

RewriteEngine On

RewriteRule ^/?([^/][^\./]*)[:;,\.]*$ index.php?action=$1&%{QUERY_STRING} [L]

Post originally taken from http://vikrant_labde.blogspot.in/