Tech Note: LGF URL Makeover with mod_rewrite

Charles Johnsonfollow me on twitter
Sun Apr 13, 2008 at 11:22 am PDT • Views: 214

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.

Advertisement

353 comments

^ back to top ^

Name:

Pass:

Register Forgot Your Password? Account Settings Re-send Confirmation (To log in, cookies must be enabled in your browser!)

Turn off ads by subscribing!
For about 33 cents a day, our subscription option turns off all advertisements at LGF!
Read more...


► LGF Headlines

  • Loading...

► Tweeted Articles

  • Loading...

► Tweeted Pages

  • Loading...

► Top 10 Comments

  • Loading...

► Bottom Comments

  • Loading...

► Recent Comments

  • Loading...

► Tools/Info

► LGF Hits

► Resources

► Never Forget

► Statistics

► Tag Cloud

► Contact

You must have Javascript enabled to use the contact form.
Your email:

Subject:

Message:


Messages may be published in our weblog, unless you request otherwise.
Tech Note:
Using the Contact Form

More Partners

Compare Electricity Prices in your area. Texas Electricity is deregulated; you have the right to choose Texas Electric Rates from among many Texas Electric Companies.

Posting with pants on.

TwitterFacebook
LGF Pages
Recent Pages

_RememberTonyC
The Jeremy Lin Phenomenon
12 minutes ago
Views: 15 • Comments: 0
Tweets: 0 • Rating: 0

Daniel Ballard
Mayor Antonio Villaraigosa Screws Over L.A. With $100 Million Credit Bubble That Could Burst Once He Leaves Office - Los Angeles
1 hour, 13 minutes ago
Views: 59 • Comments: 0
Tweets: 0 • Rating: 1

Daniel Ballard
The All-About-Me Mayor: Antonio Villaraigosa's Frenetic Self-Promotion - Page 1 - News - Los Angeles
1 hour, 14 minutes ago
Views: 46 • Comments: 0
Tweets: 0 • Rating: 1

Aigle
Jodi Rudoren Enters the Scene: Tweets or Tea Leaves?
1 hour, 19 minutes ago
Views: 22 • Comments: 0
Tweets: 0 • Rating: 0

researchok
US 'Very Closely' Watching Syrian Chemical Weapons  | ajc.com
1 hour, 28 minutes ago
Views: 46 • Comments: 0
Tweets: 0 • Rating: 0

Channeling Confucius
Susan G. Komen for the Cure's Limited Impact
1 hour, 39 minutes ago
Views: 55 • Comments: 0
Tweets: 0 • Rating: 0

Bob Dillon
End of an Era: NASA Shuts Down Its Last Mainframe
1 hour, 57 minutes ago
Views: 66 • Comments: 1
Tweets: 0 • Rating: 2

Daniel Ballard
Villaraigosa Will Chair Democratic National Convention
2 hours, 8 minutes ago
Views: 57 • Comments: 1
Tweets: 0 • Rating: 2

Bob Dillon
Chemist Applies Google Software to Molecules
2 hours, 25 minutes ago
Views: 57 • Comments: 0
Tweets: 0 • Rating: 2

Daniel Ballard
Meme: What Photographers Actually Do
2 hours, 40 minutes ago
Views: 68 • Comments: 1
Tweets: 0 • Rating: 2

 Frank says:

Not a speck of cereal.