Tech Note: LGF URL Makeover with mod_rewrite

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

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:

[Link: lgf.com…]

This would show an LGF front page entry on its own page, without the reader comments. After the revamp, this URL becomes:

[Link: lgf.com…]

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:

[Link: lgf.com…]

To show a particular comment:

[Link: lgf.com…]

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 “[Link: lgf.com…] 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? 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

► 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.

Confusion and paradox.

TwitterFacebook
LGF Pages
Recent Pages

Randall Gross
Mitt Romney: Little to Like: DNC Spoofs Romney Facebook Timeline
1 hour, 11 minutes ago
Views: 44 • Comments: 0
Tweets: 0 • Rating: 0

researchok
French Philosopher Alain Badiou on the Real Expression of Love: 'If You Limit Yourself to Sexual Pleasure It's Narcissistic'
5 hours, 19 minutes ago
Views: 70 • Comments: 0
Tweets: 0 • Rating: 0

Haywood Jabloeme
Closing the Racial and Generational Divides
9 hours, 9 minutes ago
Views: 81 • Comments: 0
Tweets: 0 • Rating: 1

Channeling Confucius
The International Response to Syria After the Houla Massacre
11 hours, 1 minute ago
Views: 89 • Comments: 0
Tweets: 0 • Rating: 0

Aziz Poonawalla
I Speak for Myself: All-American
13 hours, 5 minutes ago
Views: 123 • Comments: 0
Tweets: 0 • Rating: 5

Aigle
Mainliners Speak Truth to Jewish, Not Arab and Muslim Power
17 hours, 22 minutes ago
Views: 339 • Comments: 12
Tweets: 0 • Rating: -5

Mostly sane, most of the time.
So wake up and notice already
2 days, 8 hours ago
Views: 289 • Comments: 0
Tweets: 2 • Rating: 7

Daniel Ballard
Late Afternoon Light-Kalanchoe
3 days, 13 hours ago
Views: 265 • Comments: 0
Tweets: 0 • Rating: 5

Eclectic Infidel
City College of San Francisco Budget Update
3 days, 13 hours ago
Views: 314 • Comments: 0
Tweets: 0 • Rating: 2

MichaelJ
Apple TV Slated to Debut in December?
4 days, 19 hours ago
Views: 368 • Comments: 0
Tweets: 0 • Rating: 1

 Frank says:

Bad facts make bad laws -- Said during the PMRC hearings.