Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I'll often see a URL that looks something like this:

site.com/articles/may/05/02/2011/article-name.php

Surely all of those subdirectories don't actually exist? It seems like it would be a huge redundancy, even if it was only an identical index file in every directory. To change anything you'd have to change every single one.

I guess my question is, is there some more elegant way that sites usually accomplish this?

share|improve this question
    
By accomplish, do you mean to have the URL appear as you indicated above without actually structuring the directories that way? –  dan Feb 27 at 21:25
1  
If it were me, unless there was a good reason to have them all split up like that, I would have articles in one directory with their title giving the date info e.g. /articles/20110502_article-name.php FWIW using YYYYMMDD means that files will always be ordered chronologically, even when ordered alphabetically. This may or may not be a good thing if you have thousands of files, but it is excellent for image files. –  Steve Feb 27 at 21:44
1  
See Using Permalinks. –  dan Feb 27 at 21:48
1  
It is more common to see the "date" portion of the URL ordered the other way round eg. /2011/02/05 - this provides a more logical structure for blogs, where entries are often arranged chronologically. Also note (as suggested by dan's permalink link), URLs and file system paths are two distinct entities. One might be mapped quite closely to the other, but this is not necessarily the case. –  w3d Feb 28 at 13:58
1  
This was answered by user Dan in the comments: it's accomplished with the Apache mod_rewrite module. That will be enough for me to research the rest. Thanks! –  felwithe Feb 28 at 15:58

2 Answers 2

Actually these are often blog sites and often with static rather than dynamic content, though not always. The URL you are referring to is automatically maintained by the software which creates, recreates, or updates the site according to what is in it's database. The URL structure is often an option. I do not see the advantage to having a directory path that is a date other than allowing for topics with similar or identical article names which can often happen on a blog - especially a blog where more than one person participates in.

share|improve this answer

The subject you need to look into is called a Rewrite engine.

Basically, a dynamically generated page (eg a CMS page) needs to get parameters sent to it via the URL so that it knows what content to display. For example, if a site only needs to know the article id in order to get that article's content from the database, then that page may initially have the URL site.com?id=24.

A rewrite engine could tidy that URL up so that it becomes site.com/24 or site.com/anything/24. It just needs to know the "24"

It could even remove the id, just so long as a database query could work it out from its replacement. For example... site.com/articletitle could allow a database query to ask "what is the id of the article with the title articletitle", before generating that page.

The example you give is pretty poor, as the date is back-to-front. However, the wikipedia entry has some nice examples of it in proper use:

http://en.wikipedia.org/wiki/Rewrite_engine

(It is very unlikely that a static site would use such a directory structure)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.