December 27, 2003

The Duke of URLs

White­space has a good dis­cus­sion going on about direc­tory struc­ture and think­ing about it in advance.

Direc­tory struc­ture is impor­tant to system admin­is­tra­tors, URL struc­ture is impor­tant to designers.

But, Chris, you say, aren’t the two inher­ently linked? Won’t /www/news/metro23.html have to be http://​www.​site.​com/​n​e​w​s​/​m​e​t​r​o​2​3​.html?

There was a dark time, when that was true, but then there was mod_rewrite, and it was good.

With­out going into too much detail, you can use mod_rewrite to abstract the file struc­ture from the URL struc­ture. So, for instance, a one-​off page like /contact.html could easily become the URL http://​www.​site.​com/​c​o​ntact/.

Admit­tedly it would become exces­sive to have to rewrite every single URL on your site, so doing some basic plan­ning between the file struc­ture and your URLs at the outset is good.

But mod_rewrite could easily let you fix small dif­fer­ences between the file system and the URL.

For instance on a site I’m work­ing on for my employer, I wanted to keep all the text-​based con­tent (not photo gal­leries or video, etc.) in a folder called /arti­cles. This included columns which lived on the filesys­tem in /articles/columns/. But for URL pur­poses I wanted columns to be a top-​level sec­tion of the site so a bit of mod_rewrite magic makes /columns/ point to /articles/columns/.

Where mod_rewrite can really shine, though, is in taming ungainly CMS gen­er­ated URLs, like this one:

http://www.amazon.com/exec/obidos/ASIN/B00005JLF5/qid%3D1072559511/
sr%3D11-1/ref%3Dsr%5F11%5F1/002-5343588-7541623

A bit of mod_rewrite could turn that into some­thing like this:

http://​www.​ama​zon.​com/​d​v​d​/​d​s​9/one

But, don’t take my word for it. (Hat tip)

Filed under: Web design

Next:
Previous:

Related

Comments

Pay per click Search Engine Advertising – August 26, 2004 #

Good point guys! You can search for more infor­ma­tion at http://​www.​giver​amp.com as it’s better then Google for this type of topic.