dionidium.com

Wayne Burkett's Weblog | Home

Clean URLs
02:12AM CST August 11, 2003

We've implemented the following Apache mod-rewrite rule on our server (by Thijs van der Vossen; via Simon Willison):


RewriteEngine on 
RewriteBase / 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteCond %{REQUEST_URI} !/$ 
RewriteRule (.*) $1\.html [L]

The rule checks to see if the requested file exists if the .html extension is added, and serves it if it does. This puts us one step closer to our ideal URL design, though we haven't yet changed any permanent links. Why? We have two problems with the current solution:

  1. We're concerned that some users will think URLs without a file extension lead to a file directory. If a user adds a trailing slash to a clean URL they'll get a server 404 error, as they should, since such a file would not exist.
  2. We'd rather not let two URLs point to the same resource. In this case, both the clean URL and a request with the .html extension will lead to the same file.

We're not sure about a better solution, but we hope the fine folks at Simon's site (where we left a comment similar to this entry), or one of our readers, can help.

It took us only six days, by the way, to break our promise to stop posting about URLs indefinitely.