Choosing the right URL structure

by Mads Kristensen 20. December 2007 04:09

I’ve been working on the URL structure on the upcoming version of BlogEngine.NET. In the current version, the URL wasn’t very pretty when viewing posts on certain dates or all posts in a month. It looked like this for a specific date:

example.com/blog/?date=2007-12-19

and like this for a specific month in a year:

example.com/blog/?year=2007&month=12

That’s the way they have looked since BlogEngine.NET 1.0 and I must admit they look awful. I just never gave it much thought to improve on them.

Then the other day I gave it some thought and for some stupid reason, I thought it would be cool to use the PathInfo part of the URL instead of the query string. So now the URLs looked like this:

example.com/blog/default.aspx/2007/12/19/

and

example.com/blog/default.aspx/2007/12/

This was of course an improvement since they became much more similar and used the same logical structure. The problem is that by using the PathInfo without some kind of URL rewriting at the same time, the relative root URL changes from /blog/ into /blog/default.aspx/2007/12/19/ which of course ruins a lot of things.

Today I finally saw the light. I have no idea why it took me so long, but I guess that late is better than never. The URLs now look like this:

example.com/blog/2007/12/19/default.aspx

and

example.com/blog/2007/12/default.aspx

and because I saw the light I’ve also added the next logical step, which is to display all posts in a given year like so:

example.com/blog/2007/default.aspx

What’s really stupid is that every other blog platform uses this URL structure. I must have had my head up my butt. When I was at it I also changed the calendar URL from

example.com/blog/default.aspx?calendar=show

to

example.com/blog/calendar/default.aspx

All the old URLs still work, so no links will be broken.

The .aspx extension

Now you might wonder why the default.aspx is needed at the end of the URLs. If I had a choice about it, trust me, it would be history. The thing is that on hosted servers where you cannot touch the IIS you will not be able to pass all incoming requests to the ASP.NET ISAPI filter. Only a few extensions including .aspx do. So in order to make sure the URL will work on those servers, we need the .aspx extension. It didn’t have to be default.aspx it could be anything ending with .aspx, but I thought default.aspx was one people had seen before and wasn’t confused about.

We’ll have to wait for IIS 7 to be released before we can construct URLs without the .aspx extension on hosted servers.

You can test the new URL on this blog.

* Only $4.95/month ASP.NET & Windows 2008 + IIS 7 Hosting! FREE SQL Included

Tags:

ASP.NET | BlogEngine

Comments

12/20/2007 4:39:22 AM #

Martin H. Normark

Having the title of the post in the URL, actually improves search engine ranking a little. You know when you search for "URL structure" these words are highlighted in the URL on the search engine results page of most search engines.

But the year/month/day structure is also nice to have - so maybe you should combine the two to make this URL?: example.com/2007/12/19/Example-blog-post.aspx

This also makes it possible to have more than one post per day - What would actually happen to the example.com/blog/2007/12/19/default.aspx if you post more than one today?

Martin H. Normark Denmark |

12/20/2007 4:42:00 AM #

Martin H. Normark

God damn. I have to wake up sometimes. I read it like it was a URL to a single post.

Martin H. Normark Denmark |

12/20/2007 4:49:55 AM #

Mads Kristensen

This URL structure doesn't affect posts and pages in BlogEngine. It is used when you click on the calendar widget (on the right) or on the archive list of months (also to the right). If you have more than one post on a single day, both posts will be displayed like these ones blog.madskristensen.dk/2007/10/09/default.aspx

The URL for posts can be added the year and month by flipping a switch in the settings page in BlogEngine. I don't use it on this site because I don't have two posts with the same title (or Slug). If I would, it would look like this blog.madskristensen.dk/.../...pping-in-ASPNET.aspx

I just don't like the year and month in my URLs because they don't tell me anything relevant about the post I'm about to read. Besides, the date is written on the post itself.

Mads Kristensen Denmark |

12/20/2007 4:52:12 AM #

davidee

I like your way mads! nice!

davidee Italy |

12/20/2007 5:43:15 AM #

Dave Transom

Another way might be to drop the monotonous default.aspx and simply make the last 'folder' the file instead.

/2007/10/09/default.aspx becomes /2007/10/09.aspx
/2007/10/default.aspx becomes /2007/10.aspx
/2007/default.aspx becomes /2007.aspx

It shortens the url slightly, and I think, makes it more concise. It also falls prey to the same issues as with default.aspx, in that if you change the url, and think it's going to find the default document i.e. you enter "/2007/10/09/", unless you have a 404 mapping scheme set up, it's not going to find the file.

Dave Transom New Zealand |

12/20/2007 6:30:51 AM #

Kevin Collins

Very happy to see these improvements Mads! A couple more requests along these lines:

1. For those of us that do have access to configure IIS, could BlogEngine please have the option to remove "default.aspx" so that all URLs end with just a trailing slash.

2. I'd like the option of making URLs lower case. I understand that could be done at theme level, but an option in the admin would make it easier.

Kevin Collins United States |

12/20/2007 7:43:34 AM #

Zack Owens

How about you give people the option so that:

1) People with IIS 7 now can have extensionless URLs
2) People with IIS 6 after IIS7 is released can go back to having the extension

It's only logical.

Zack Owens United States |

12/20/2007 8:33:48 AM #

Darius

As always, another great post by the great Mads Smile

Darius Iran |

12/20/2007 9:43:46 AM #

Justin Etheredge

Yep, those urls look much better. Very nice.

Justin Etheredge United States |

12/20/2007 2:14:38 PM #

Andreas Kraus

You should automatically 301 redirect the old query string URLs to the new ones, otherwise it's treated as duplicate content by searchengines.

Andreas Kraus Germany |

12/20/2007 5:43:04 PM #

Dan Atkinson

Is it possible to go to a particular day and, depending on whether there is only one post there, then comments are displayed, as if it were actually the post link (or the contents of the page are redirected altogether)?

Just a thought, that's all!

Dan Atkinson United Kingdom |

12/20/2007 8:00:21 PM #

Mike van Zandwijk

Hi Mads, great improvement. One point of feedback:

When you use something like /2007/default.aspx, the site displays the paged posts correctly. If an user would click on 'previous posts' (i.e. default.aspx?page=2), BE.Net generates a 404 error.

Hope this helps!

Best regards,
Mike

Mike van Zandwijk Netherlands |

12/20/2007 10:34:34 PM #

Josh Stodola

Welcome to the biggest can of worms you have ever opened Smile

I had a good ol time setting up the URL structure for my blog, in other words, I have already fought this battle.  I ditched the default.aspx in my URLs becuase it is so redundant and somewhat annoying.  I must tell you that you do not need to do anything with an ISAPI filter to get rid of "default.aspx".  All you need to do is create the actual folders on the server and put an emtpy file named "default.aspx" in there. That is kind of a pain in the ass, but once you set it up for one month, you can copy it.  Once you set up a years worth of folders, then you can just copy that. I will admit that it is not the most elegant of solutions, but it works like a charm; invoking /blog/2007/12/ will get to ASP.NET becuase IIS will see the default document in the actual folder and route it properly.


I finally settled for the following URL structure:
~/archives/year/month/post-title-goes-here.aspx
~/archives/year/month/
~/archives/year/

If on any of the requests only 1 blog post is returned, then it displays the whole post along with the comments. Works great! Good job on cleaning up the URLs for BlogEngine.NET, it was something that has gone quietly unnoticed.

Josh Stodola United States |

1/2/2008 6:43:35 PM #

Kåre Per Hansen

Follow up on Josh.

If your webhotel lets you set the 404, you can let it point to the error404.aspx file.

Let the error404.aspx creates the missing folder with a 'default.aspx' file in it and afterwards redirect to the folder.

The folder structure will be build over time and you don't have to do any manual work.

Kåre Per Hansen Denmark |

1/2/2008 6:54:17 PM #

Kåre Per Hansen

About the year and month in urls I do think they tell a lot about the post.

For example this post might be less interesting to look into after the release of IIS 7. And at that time you might prefer to look for similar post, but with a date after the release date.

When I search for posts about 'Linq' I go for posts written in late 2007 and normally leave out those written earlier and those where I don't know when they have been written (and I am just too lazy to go into a post to see the date).

So in the "competition" for which post to choose those with a date score higher for me than those without.

Kåre Per Hansen Denmark |

1/8/2008 3:43:14 AM #

Catto

Hey Now Mads,
The URL's look better.
Thx 4 the info,
Catto

Catto United States |

8/28/2008 9:48:42 AM #

Tareq

Hey Mads,

Can you pouint out how to change the url format if I want to remove /page/ and /post/ from the url?

Thanks

Tareq United States |

Comments are closed

About the slave

Mads Kristensen Mads Kristensen
Web developer at ZYB and founder of BlogEngine.NET. More...

LinkedIn ZYB Facebook Last.fm Twitter View Mads Kristensen's profile on Technorati

The Lounge

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008