Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Oh, .htaccess hurts my head.

So, I have a webpage which has a pretty URL of though actually lives at

I achieve this using an .htaccess line of...

RewriteRule ^(radio|tv|magazines|newspapers)/jobs$ /content/directory_jobs.php?section=$1

This same page has an optional ?pages= query string - so you can go to and see the second page.

The above .htaccess line, however, doesn't add this pages variable: with the result that the underlying PHP script doesn't see a 'pages' variable.

Can I tweak the above .htaccess line to ensure that I do pass a 'pages' variable if it exists? Or do I have to have two .htaccess lines for every page like this?

share|improve this question
up vote 6 down vote accepted

Just add the QSA (Query string append) flag

RewriteRule ^(radio|tv|magazines|newspapers)/jobs$ /content/directory_jobs.php?section=$1 [QSA]

With QSA flag /radio/jobs -> /content/directory_jobs.php?section=jobs
/radio/jobs?foo=bar -> /content/directory_jobs.php?section=jobs&foo=bar
/radio/jobs?foo=bar&boo=bosh -> /content/directory_jobs.php?section=jobs&foo=bar&boo=bosh
mod_rewrite will figure out if it needs to add a ? or a $ so for a rewrite rule

RewriteRule ^([a-z]+)$ /$1.php [QSA]

/something?foo=bar -> /something.php?foo=bar

share|improve this answer
D'oh. Brilliant, thank you. – jamescridland May 28 '11 at 19:03

Your Answer


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

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