Redirecting Web Pages to Specific Addresses
The problem is pretty straightforward: the web site redesign causes the structure to change, thus the old addresses become invalid. Since you don't want the users to get the dreaded error 404: Object not found, there are a couple of options available to you (if you're using IIS – Internet Information Services, that is).
You could just change the error page to match the style of your web site and inform the visitor about the now missing page or just make the redirection to your new starting page. This is a bit unfriendly to the visitors if you kept the old content since they have to find it themselves. It would certainly be better to redirect them directly to the new address of the old content. But still it's not a bad idea to do this. It's an easy way to keep the users on your website even when they encounter invalid URLs by whatever reason. Just open up the Custom Errors tab of the virtual directory or web site properties and set the desired URL for the error 404. But don't forget that you have to enter the complete path starting from the root of the site, for example:
If you want to make a different redirection for each page you could just keep the old pages but instead of having any actual content they would just make a redirection to the correct new address. This solution has two problems:
- It's difficult to maintain if you have many pages.
- You're stuck with the client side redirection, i.e. meta refresh tag.
To make the redirection server side you could use the redirect options on the Home Directory tab of the virtual directory or web site properties. But they have some serious limitations and tend not to work as expected, even more so because the documentation doesn't explain them very well. But there's no reason to worry, I have a better solution for you. Setup a special 404 URL on the Custom Errors tab as already suggested. But this time use an
aspx page for it. The supplied query string (
Request.QueryString) contains the missing URL which you can parse out and use to determine the correct new address corresponding to it. For a few pages a simple
switch clause will do but nothing prevents you from having the mappings stored externally, in a special file or a database table for example. All that's left is to make a
Response.Redirect to the new address.
There's one more thing to take care of. If you moved your site to a new subdirectory and chose the last suggested solution, don't forget to setup a similar simple starting page which just redirects the visitors to the new starting page. Trying to open the site without this page will namely cause an error 403: Forbidden, because a directory listing will be attempted which you have (hopefully) prevented.