views:

86

answers:

2

What are the standards for managing URL redirects if you base your URL's off properties of the data that might change a few times, like the "title"?

I have a website with lots of images and I want to make the urls look like this:

http://www.mySite.com/images/132123/my-cool-image-title

Now say a bunch of people bookmark the image, and a week later I change it to:

http://www.mySite.com/images/132123/renamed-image-title

So now there has to be a redirect for the people that bookmarked the old one... Now lets say that happens on average 3 times per image. That means I'd have lots and lots of redirects to map. I'd have a database of redirects it seems.

What is best practice in this case, assuming I want to use pretty urls and not base it on some universally unique id, and that I'd like to reap as many benefits of SEO as possible?

+1  A: 

Well I don't know what the downvote was about, this seems like a perfectly valid question to me.

My recommendation would be that if you know in advance you will be changing the data, it probably shouldn't be in the URL in the first place. If this is a requirement (perhaps its important for SEO or you are creating a blog or something, you have some choices:

  1. Forget the old URL and use only the new. Probably not a good way to make friends ;)
  2. Keep the old URL and accept the fact that the title and URL do not match now. This might be accomplished by each post having a slug field where the URL text is stored, separate to the post's actual title.
  3. Keep the old URL and allow for new ones. A method for doing this might be to have a separate table which maps slugs to posts, each post having one or more slugs. That way, any number of changes are catered for.

If possible changes and backwards compatibility are a requirement, I'd go with something like option 3. Its certainly better to have it built in to your app than have to manage growing .htaccess files full or URL rewrite rules or something.

Splash
how viable is option 3 do you think? thanks for this answer :)
viatropos
I don't see any issues with it. It'd be a lot easier if the system was designed this way for the word go - retrofitting it into an existing system which was not designed with this in mind is harder. But I can't think of anything which makes it a total no-go. I have hit the same issue in my blog and will probably use some variant on this idea to address it.
Splash
Also, bear in my that I've written this answer assuming the URLs are handled by the application (e.g. routing in most common mvc web frameworks) and not by the web server. If you are using url rewriting provided by the web server, you are constrained by whatever methods it provides - most likely a text file (or set of) with each rule defined within.
Splash
+1  A: 
skyflyer