tripalot.com > travis > blog

PHP Handler

Over the past month or two, I have updated all of my sites' URLs to no longer include the HTML filenames.  So, instead of /games/catan.htm the URL is now /games/catan/. The latter is (I think) more SEO friendly, and allows me to switch to make the page dynamic later without changing the URL again.

I'd already converted a few sites to the no-filename approach, which resulted in each HTML file being called index.html.  This worked, but when I opened a bunch of pages in a text editor, each tab said "index.html" which made it hard to tell them apart.

So this time I decided to keep the HTML files named uniquely (e.g., catan.htm).  In order to get the sites to work, I wrote a PHP handler to parse the URL and read in the correct file.  This also lets me add global features, like a favicon, google analytics, and a google plus one button to each page.

To be able to view my sites locally before uploading, I setup a local web server, and, for times when I want to view the file without a server, I wrote a JavaScript handler to rewrite all the links in the page to point to the correct local pages.

So the end result is that I was able to keep the HTML files relatively intact (with only link urls changing), named distinctly (not all "index.html"), viewable locally and online, and now with google analytics and favicons automatically added.

All this programming was a lot of work, but it's a one-time effort, and lets me start using Web 2.0 features in my sites, something I wasn't able to do before.

Leave a Reply