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

Starting with something as simple as:

RewriteRule ^(.*)$ index.php?page=$1

What if I also want the following to work:

RewriteRule ^/foo$ /index.php?page=foo #/foo IS a directory

This seem to work ONLY if the R flag is set, but then the full non-pretty url is written. Thus it seems I can REDIRECT existing directory, but not rewrite them... Maybe with an .htaccess inside the directory itself? Or some PHP magic in /foo/index.php like header(/index.php?page=foo)? Will it work? Will it be HTTP standard/search engine optimized?

Please help!

PS: The oddest idea occurred to me: redirecting /foo to /not-a-dir, and then rewriting /not-a-dir to /index.php?p=foo should theorically work... But... Come on... Really?!?

share|improve this question
why do you need the /foo directory anyway ? are there any content inside you need to access by url such /foo/something ? – m0ntassar Dec 17 '12 at 10:06

There's an option to mod_rewrite to make it handle directories instead of passing them to mod_dir:

RewriteOptions AllowNoSlash

There's more information about this at the apache documentation site.

share|improve this answer

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.