Directory Structure

December 27, 2003 | View Comments (16) | Category: Web Mastering

Summary: The overlooked importance of the directory structure for a website is discussed.

While working on the new company site I came across some sections that I felt deserved their own directories all together. This got me thinking if whether every section on the site should have its own directory. Does anyone use certain criteria when it comes to their directory structure or is this just an afterthought?

Usually sections of a site that can be clicked on from the global navigation only get a filename because all of the content for that section is usually on one page. Types of content that warrant their own folders are usually ones that house multiple files such as an Articles or News directory. I am going to have an Articles section on the 9rules site and am contemplating whether I should create an articles.php file in the root directory that links to all the articles or have an index file under an articles folder. Currently I am leaning towards creating the folder with the index file as this would keep the site more intuitive.

But then I wasn't sure whether or not the Contact page should have a contact folder with an index file or if it was okay to just use contact.php under the root directory. Though the site will start off small there will be frequent updates to both the Articles section and the News section, which in turn will help the site grow. Therefore, it is important to develop a quality directory structure more so to prevent linkrot than anything.

This is definitely an overlooked feature of websites. Although the design and content may be the two most important issues, the underlying structure of a site should not be something that is filled in. If you plan on having a site that will be around for many years and will experience organic growth then you should make sure you have the right seeds planted first.

Trackback URL: http://9rules.com/cgi-bin/mt/mt-tb.cgi/86

Comments

#1

You're right — structure is often overlooked. 'Contact' doesn't seem like a huge section so I'd stick it in the root directory. My site will be slightly easier when I come to make it, one folder for articles, CSS, PHP, archives (older posts stored as rss files) and philosphy. Files, images, stylesheets, data etc. stored in the folders for their respective sections. I plan to have enough content to warrant the use of folders, but if I don't at least it'll look neat :)

David House

#2

I don't always do it, but I prefer to make each section a directory with an index. Mainly because it's a lot easier to remember the URL. For instance on the Apple site you can link to just about anything without going to the site first. www.apple.com/itunes/ will go to the itunes page. www.apple.com/iphoto/ will go to the iPhoto page, etc. You don't have to remember if it is www.apple.com/iphoto.htm or maybe it was .html or .php or .cfm, etc. You just type the apple.com URL, then the name of the product you want and it goes.

But like I said I don't always do that. It's pretty easy to set that up to all be automated in Movable Type though, which makes it much easier to deal with.

Derek Rose (http://www.twotallsocks.com/)

#3

I wish that years ago I'd just given every major page it's own directory and ended every link like this: "...com/directoryname/" so that I could have an index file in any language. Now fear of link rot has me sticking with the old .html extensions where .shtml would be better.

A co-worker of mine always says, "Be careful of interim decisions, the first way that you hack something together will often be the last and remain that way for many years."

Nils T. Devine (http://www.nilsdevine.com/)

#4

I think that you missed a point. You can, read should, separate the file structure and the url structure. I explain.

I make a file structure according to programming needs (separation between the templates, the logic files, the configuration files etc.) and I make a structure for the site navigation.

Using url rewriting this is very easy and it solves the problem you pointed out. Indeed you can hardly imagine the way your site will grow over the years but on the other hand for your visitors' sake, your content should be always available at the same url. Hard linking the content and the files does not allow this to be changed at a later time where as if you use url rewriting, you can change as many times as you want your file structure, your visitor won't even notice.

JMF (http://www.dyingculture.net)

#5

This is definitely something that isn't thought of enough. How many MT blogs are out there with each entry's permalink just some number with a file extension, all thrown into some archives directory? While that's fine with a small number of entries, when you start to accumulate a lot of entries, that's just not manageable.

milbertus (http://www.milbertus.com)

#6

I make directories for nearly every section. As a previous poster mentioned, apple's site is a terrific example of this.

Lately it seems a few folks have been stripping the files extensions from their files, ex: http://www.blah.com/files where files is actually files.html. Why add another method when you can just make a directory with and index.x. I believe they do this in order to avoid the confusion of whether the user has to type out files.php, files.html, files.htm - but why not just create a directory and stay standard and simple at the same time? Another question, would an attempt to load http://www.blah.com/files/ break the attempt by requesting a directory instead of a file?

Sorry if this went a bit off-topic.

charles (http://enure.net)

#7

When using a CMS or other server-side technology to generate your pages, the URL doesn't match with files or directories.
Most modern server-side technologies work with objects, resources or otherwise abstracted items, not with files. File-based sites tend to be a mess to manage.

Gabriel Mihalache (http://www.individualism.ro/)

#8

I love mod_rewrite.

The website I am working on right now is run by several database-driven PHP scripts. I use mod_rewrite, so everything to the user looks like a folder. For example, the archive page, which is really "scripts/redirect.php?page=archives.html", shows up as "/archives/".

Forrest

#9

I've worked on quite a few huge sites with very complicated IAs over the years. I also know what it's like to work with a horribly organized directory structure.

My advice is to keep it simple, logical and neither too shallow or too deep. I guess the main thing is to really think about it and do what you think is best for the site your building.

For example, on our the http://www.Seattlechildrens.org site/ which I manage and built the directory structure for I only go as deep as I need too.

I only break out a new folder if there is more than say 10 or so files in it and otherwise it moves up to the next folder. But it depends.

For example we have a directory of services that has say 200 static pages. These are grouped into about 5 sections like this:

dos\clinical\
dos\administrative\
dos\etc\

Some of the listings have one page associated with them, and a few have many. If they have more than one page they get their own folder like this:

dos\clinical\craniofacial\

Every file is named with plain english and the path is the same as the url for most things. We do use redirects to make somethings make more sense to the user.

I think for your contact example, depending on how many pages you have, you may just want to put it in the root folder.

One of my sites is only about 25 pages big and will only grow a little bit. I keep all the .php files in the root directory. I have other directories for images, scripts, etc.

I can't stress enough the fact that you want to keep your files organized logically if you are working with a team or may ever hand the site off to someone else.

I know the pain involved with taking over a poorly organized site and I don't ever want to inflict that on someone else.

Keith (http://www.7nights.com/asterisk/)

#10

Mod_rewrite is your friend, use it wisely and you can organize your files however you need BUT stil provide hackable URLs to your users.

quote/
Gabriel Mihalache wrote:
Most modern server-side technologies work with objects, resources or otherwise abstracted items, not with files. File-based sites tend to be a mess to manage.
quote/

But most (not all) CMS sites provide URLs to users that are a mess. Put your users first, and use mod_rewrite. You can have your cake (and easy to navigate site for the end user) and eat it too (a site that's well organized on the back end)

Chris Heisel (http://www.heisel.org)

#11

"You don't have to remember if it is www.apple.com/iphoto.htm or maybe it was .html or .php or .cfm, etc. You just type the apple.com URL, then the name of the product you want and it goes."

You can configure most web servers to process files regardless of specifc file extensions; your files need not have any extension at all. So, www.apple.com/foobar may point to the index page of directory foobar, or to a page named foobar in the root directory. There are some advantages to hiding the implementation details, not the least is that you can change your server code without breaking URLs.

Of course URLs need not map to any actual physical directory structure or existing file, so really you need first to decide how the site should behave (all URLs are valid? Use POST? GET? Use PATH_INFO to disguise query strings?), then write the server code to produce that effect.

You pick a physical file layout that suits the needs of developers and security, and a URL scheme for the users.

James (http://www.jamesbritt.com)

#12

It depends on the complexity of the site and the nature of the site.

For the website of my primary employer, which is mostly informational stuff and has an excessively large number of pages, I put each division in its own area with its own media directory. Subsets of a given division are in some cases in a subdirectory of that division, in others they merited their own based on complexity.

If I'm doing a fusebox application, though, I create display, action, and query folders to store the different types of files and everything's accessed through /index.cfm or whatever. (sometimes I put that stuff below the webroot so people can't access it directly, but it's usually not worth the bother.

If it's a small site, a directory structure beyond having a media folder isn't really needed.

If all you're concerned about is URLs, mod_rewrite or just htaccess redirects work fine.

JC (http://thelionsweb.com/weblog)

#13

Ah, mod_rewrite. Wouldn't it be lovely? However, my host only has mod_rewrit (note: no "e"), an undocumented version with mysterious gaps in its functionality. They can't or won't provide documentation or the source code. Yes, I know that's a GPL violation - what can I do when they won't answer any questions about it? So I get by with mod_alias and others, but it's not the same.

Eric TF Bat (http://flurf.net/)

#14

I agree that for big/CMS sites mod_rewrite URL mapping is the way to go. Unfortunately mod_rewrite is _hard_ (for us mere mortals anyhow). For sites that don't use URL mapping, I think the URL should be non-crufty, easy to guess, and permanent. Here are some links that might be interesting:

TBL on not changing the URL:
http://www.w3.org/Provider/Style/URI
TBL advocates no extension, then you can just set up files to check in order of preference in .htaccess

Neilsen on URL as UI:
http://www.useit.com/alertbox/990321.html

Matthew Thomas on;
- Interface Cruft:
http://mpt.phrasewise.com/stories/storyReader$374

- The perfect blogging system:
http://mpt.phrasewise.com/2003/05/02

- Cruft in present blog software URLs:
http://mpt.phrasewise.com/2003/07/26

Evolt on URL mapping with Apache + PHP:
http://evolt.org/article//18/22880/

MT Setup;
- Dive Into Mark's URL slugs for date+title:
http://diveintomark.org/archives/2003/08/15/slugs
http://diveintomark.org/about/templates/

- Mar Orlygsson using regex for date+title:
http://mar.anomy.net/entry/2003/06/22/17.15.00/

My method is based on using Mark Pilgrim's code with Brad Choate's MT-KeyValues plugin
http://www.bradchoate.com/past/keyvalues.php
I use KeyValues to replace the article title; instead of a dirified title (I like long, informative ones), I can specify exactly what I want.
http://oli.boblet.net/2003/08/17/rtfm
(eg the title of this post is "Read the funky manual", not RTFM, with a KeyValue of "url=rtfm" :-)

Woah, sorry that was long. I may as well post it myself :)

oli (http://oli.boblet.net/)

#15

Here's a good link on site organization which got me started -
http://www.theobvious.com/archive/1998/11/02.html

A bit off-topic but directory and filenames are also used by SEO's to add keywords for search engines...

jinesh (http://jinesh.org/)

#16

I've done sites where I wish I'd been more generous with the sub-directories when I've ended up with getting on for 100 pages in a folder. Retro-fitting is a pain.
I've since learnt from this and make folders wherever I think there is a possibility of the section expanding in the future.

Adam (http://www.liptrot.org)

Keep track of comments to all entries with the Comments Feed