Show top rated links | LinkViewer
Tech Note: LGF URL Makeover with mod_rewrite
Sun, Apr 13, 2008 at 11:22:34 am PDT
This weekend our aging, creaky, rather unfriendly URL scheme got an extreme makeover, courtesy of the Apache htaccess file and mod_rewrite.
The cool thing is that this redesign doesn’t break any old URLs; if you’ve bookmarked an LGF page, or if you follow an older link from another site, it will continue to work as always.
The old scheme used HTTP query strings, in that ugly sort of techie way you’ve seen many times; for example:
http://lgf.com/weblog/?entry=29585_Windows&only
This would show an LGF front page entry on its own page, without the reader comments. After the revamp, this URL becomes:
http://lgf.com/article/29585_Windows
Isn’t that prettier? And it has the advantage of being easier for search engines to index, too.
To show an LGF page with reader comments, the URL would be:
http://lgf.com/article/29585_Windows/comments
To show a particular comment:
http://lgf.com/article/29585_Windows/comments/#c0053
Internally on the server, all of these new types of URLs are converted to their old style addresses with those ugly query strings, so none of the LGF code needed to change. Which is always good.
For the geeks in the crowd, here are the mod_rewrite rules that accomplish this feat of prestidigitation:
RewriteRule article/(.*)/comments/(.*) /weblog/?entry=$1$2
RewriteRule article/(.*)/comments/ /weblog/?entry=$1
RewriteRule article/(.*) /weblog/?entry=$1&only
UPDATE at 4/13/08 1:19:48 pm:
The Opera web browser wasn’t liking this new scheme, because it has a bug in the way it executes Ajax calls.
In a nutshell, I use the HTML <BASE> tag to set the base URL to our weblog folder, so that files referenced with a simple pathname (e.g. “logo.gif” instead of “http://lgf.com/weblog/logo.gif”) can be found when the above URL redirection scheme is used. Without the BASE tag, the browser requests those files from inside a nonexistent folder named /article/.
But Opera (including the latest version as of this writing) doesn’t properly pass the base URL to Javascript Ajax calls. Apparently they need a little bit better communication between their HTML and Javascript engines.
The fix was annoying but relatively easy: just change the Ajax calls to use absolute path references to their scripts.
353 comments
- Comments are open and unmoderated, and do not necessarily reflect the views of Little Green Footballs.
- Obscene, abusive, silly, or annoying remarks may be deleted, but the fact that particular comments remain on the site in no way constitutes an endorsement of their views by Little Green Footballs.
- Posts that contain phone numbers, street addresses, email addresses or other personal information will also be deleted, as will posts that consist only of a variation on the word, "First!"
- Comments that advocate violence will be cause for immediate banning with no appeal.
- REMEMBER: posting comments at LGF is a privilege, not a right. Abuse that privilege, and your account will be blocked.









