Mod_rewrite pretty url when domain/foo is a directory

Posted by ModRewriter on Server Fault See other posts from Server Fault or by ModRewriter
Published on 2012-12-17T08:58:38Z Indexed on 2012/12/17 11:04 UTC
Read the original article Hit count: 307

Filed under:
|
|

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?!?

© Server Fault or respective owner

Related posts about apache2

Related posts about mod-rewrite