Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using this -

RewriteRule ^/one/([a-zA-Z-]+)/(two|TWO)/(three|THREE)/([a-zA-Z0-9()-.\?\=]*)/?$ /city/city-search.php?c=$1&t=$2&pf=$3&iptnr=$4

I am caling - and want to access variables in city-search.php like ... one , pune, two, three and ptnr value

but as string find '?' in (index.php?ptnr=xyz) it breaking....please help me is not able to redirect this...

share|improve this question

I don't think there's a way to examine the entire URL including parameters in one hit. You need to examine anything after the ? separately with a QUERY_STRING, eg.
RewriteCond %{QUERY_STRING} ^param=blah(.*) [NC]

share|improve this answer
i use it its work for me but my parameter is not mandatory.... so what should i do..i use RewriteCond %{QUERY_STRING} ^ptnr=(.*)$ – Anuj Ji Aug 31 '10 at 12:22
If that's what you're looking for, to rewrite anything with a pntr parameter first (note that this will match more than one parameter but only if ptnr is first) then use this RewriteCond then have a RewriteRule underneath – James L Aug 31 '10 at 16:29

You have to escape the ? since it's a special character in regular expressions.

So instead of using ? try \?

share|improve this answer
please check the above rewrite rule....already escaped – Anuj Ji Aug 31 '10 at 10:54

Normally you don't include the QUERY STRING in your matching pattern. Then you just add %{QUERY_STRING} to your rewrite rule. Example:

RewriteRule  ^/(articles)/([-a-z]+)-([0-9]+)/$  /index.php?cat=$1&id=$3&rewrite=$2&%{QUERY_STRING}

The Apache Documentation writes:

Note: Query String

The Pattern will not be matched against the query string. Instead, you must use a RewriteCond with the %{QUERY_STRING} variable.

share|improve this answer
thanks a lot got started to respond now...its really great help today – Anuj Ji Aug 31 '10 at 14:19
No problem.. just vote me up if I helped you ;) – Jan. Aug 31 '10 at 16:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.