IIS redirect based on domain/ ip address

iis-7

We have domain http://mysite.companyname.net which points to an ASP.net MVC site.

We also have a dedicated link from our office to the same server at the data centre in Manchester.

Is it possible to redirect any url belonging to mysite.companyname.net to http://mysite.companyname.net/maintenance.aspx.

However when we access it via it's internal machine name i.e. http://IIS-SERVER001 it works as normal

This is purely so we can test the site we deployed but customers can't use it while we're testing.

Also occasionally we need to redirect all uk customers to a certain url but allow German customers through e.g. example on uk bank holidays. how is this possible?

Best Answer

You would use the IIS Rewrite module for your first question.

It allows you to set up rules to change/block requests based on various things including the host name.

The documentation for the module is okay and there are lots of questions about it on here as well.

The bank holiday problem is a bit more tricky as the builtin URL rewrite rules can not handle such a requirement.

You may be able to write a Custom Rewrite Provider` for the URL rewrite module, otherwise you have to add such logic to your own http module which handle all requests coming in.

The problem is you don't want to do an IP location lookup on every request, so you would need to cache this.

It would be much easier if the Germans would always go to `

http://mysite.companyname.net/de/*

then you can have different rules for that part of the site.