views:

21

answers:

1

I would like to reorganize the directory structure on a hosted website (i.e. I can not go in and configure the IIS settings).

Say I had 3 files in the root directory:

  • fruitcake.html,
  • chocolateCake.html, and
  • appleMuffins.html

Now, I want to move them to a new folder called Recipes. This is easy enough, but there are a lot of existing links out there that point to the other files.

How would I construct a 404.aspx page to read in which file was in the address bar, then update the browser to go to the new location?

+1  A: 

I'd take a look at the IIS Redirect Module rather than creating your own 404 handler to do the redirects.

EDIT

You can configure the rules in web.config, but it does have to be installed on the server first.

If that's not installed on the server, UrlRewritingNet does a similar job with an HttpModule, so you only need to upload the DLL and reference the module in web.config. Once the module is registered in web.config, you can add the redirect rule with something like

<urlrewritingnet>
    <rewrites>
        <add name="recipies"
virtualUrl="^~/(fruitcake|chocolateCake|appleMuffins)\.html"
destinationUrl="~/Recipies/$1" ignoreCase="true" redirect="Application"
redirectMode="Permanent" />
    </rewrites>
</urlrewritingnet>
stevemegson
This site is being hosted elsewhere. I'd have to write something for a web.config or ...?
jp2code