Tech Note: LGF URL Makeover with mod_rewrite

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

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.

Brevity rocks.

TwitterFacebook
LGF Pages
Recent Pages

researchok
'I Was Looking Forward to a Quiet Old Age': Instead, Etta Shiber, Helped Smuggle Stranded Allied Soldiers To Freedom
4 hours, 36 minutes ago
Views: 60 • Comments: 0
Tweets: 1 • Rating: 0

Daniel Ballard
Late Afternoon Light-Kalanchoe
12 hours, 18 minutes ago
Views: 99 • Comments: 0
Tweets: 0 • Rating: 4

MikeySDCA
Colin Powell Endorsed Same-Sex Marriage Once It Was Safe, More Evidence He's Hardly a Great Leader.
12 hours, 21 minutes ago
Views: 130 • Comments: 1
Tweets: 0 • Rating: 1

Eclectic Infidel
City College of San Francisco Budget Update
13 hours, 10 minutes ago
Views: 119 • Comments: 0
Tweets: 0 • Rating: 0

Michael McBacon
Kansas governor signs 'Shariah bill' to ban Islamic law
17 hours, 41 minutes ago
Views: 230 • Comments: 6
Tweets: 0 • Rating: 5

Aigle
National Geographic Traveler Veers Off Track
1 day, 17 hours ago
Views: 451 • Comments: 7
Tweets: 0 • Rating: -5

MichaelJ
Apple TV Slated to Debut in December?
1 day, 18 hours ago
Views: 227 • Comments: 0
Tweets: 0 • Rating: 1

Ascher
Israeli Who Saved Turk on Everest: You Never Abandon a Friend - Israel News, Ynetnews
1 day, 20 hours ago
Views: 298 • Comments: 1
Tweets: 0 • Rating: 3

Haywood Jabloeme
The Harrassment of Patterico & Its Roots in Left-Wing Activism
1 day, 20 hours ago
Views: 519 • Comments: 2
Tweets: 0 • Rating: 4

Curt
Brian Banks: (Video) Falsely accused of rape speaks out
1 day, 22 hours ago
Views: 272 • Comments: 2
Tweets: 0 • Rating: 5

 Frank says:

Yeah, I tell them to change the channel if they see some guy in a brown suit with a telephone number at the bottom of the screen asking for money. -- on being asked by Tipper Gore if there was anything on the TV he _didn't_ allow his kids to watch ...