SEO / SERPS

Building a Site With Clean URLs

As an aside in my post about Cambrian House I posted some code for making pretty URLs. A few people (no, not CH) have asked for a little more info, so I've written up an explanation of that code.

PHP makes it very easy to create bad URLs like /member.php?id=8. Those are bad because web spiders don't like to crawl URLs with GET variables, some browsers don't cache any GET URLs, they expose that you use PHP (when the visitor should never even know), and they're just downright ugly and hard to remember. I'm going to present a way to build a PHP/Apache site with clean URLs.

Let's look, line-by-line, at the contents of .htaccess. While writing this article I found a more elegant equivalent in the Wordpress code, so I'll present that here:

# Tell Apache to load mod_rewrite.
RewriteEngine On
# Rewrite URLs for the location starting at /
# Note this is URL location, not a path to your web root.
RewriteBase /