IIS Redirect Moved Files
I would like to reorg开发者_运维百科anize 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?
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>
精彩评论