First of all this is a MVC4 site running on an IIS server. I am a developer, but in this case, the site is built by a 3rd party and while I have access to the IIS server, I don’t have access to the source code, so I can’t change route rules in the Global.asax. Being that it is MVC, I have issues I wouldn’t have in a non-MVC site (routing issues).
FYI: The business reason for this is that the 3rd party building this website won’t complete the code under the /Greensboro section before we release print materials with that url, so we need to send visitors to the root site rather than showing a 404 or other error message.
My first thought was to drop in a HTML page with a meta refresh redirect tag, but this being MVC, and because meta tags are 100% reliable, I skipped that.
My second thought was to add an Application under the site in IIS and then use the Http Redirect in IIS. This failed because of issues with the web.config file and dlls not being present in the application I created. I tried fixing the web.config and placing copies of the main bin in the application folder, but fixing each issue leads to another issue, (and on and on) and it is getting really messy, so I decided to look at other alternatives.
The final solution was quite simple so I won’t bore you with all the mis-steps.
- To make this work, create a virtual directory under your website (not an Application). I’ve named my virtual directory ‘Greensboro’ and pointed it to a new folder I created (you just create a new folder in your site and point it to that).
- In IIS, click on your new virtual Directory, then double click on the Http Redirect icon.
- Set the redirect route to where you want customer redirected (http://www.mysite.com/).
- Check the box for ‘Redirect all request to exact destination (instead of relative to destination)’
- Click ‘Apply’
So this works very nicely as a Virtual Directory, but can have you pulling your hair out if you were to use an ‘Application‘.