More quick-not-dirty PHP

For larger web projects I’ve moved almost exclusively to Django, but PHP is still handy. Recently I wanted to quickly (really quickly) make a flat-heirarchy site with dynamic pages, with clean urls like example.com/foo and example.com/bar.

I could do this with several directories containing index.php files, but I want to use the Google Maps API on several of these pages, and the separate directories would entail separate Google Maps API access keys – a pain.

First I added this .htaccess file to the docroot:

RewriteEngine On
RewriteRule ^([a-z]+)$ /$1.php [P]

Then I created my page scripts as foo.php and bar.php and so forth; Apache mod_rewrite takes care of the rest.



Share: