Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Oh, .htaccess hurts my head.

So, I have a webpage which has a pretty URL of foo.com/radio/jobs though actually lives at foo.com/content/directory_jobs.php/?section=radio

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 foo.com/radio/jobs?page=2 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
add comment

1 Answer

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]

Example;
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
add comment

Your Answer

 
discard

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.