Iis – How to redirect requests coming on one domain to another domain but with parameters

iisrewrite

We have a website that is hosted on IIS7 and which is bound to several domains. The site is localized in multiple languages and part of the URL holds the language code, for example www.mysite.com/en, www.mysite.com/cs, www.mysite.com/hu, etc.

When the user requests the website under a country level domain, we would like to redirect them to the main (.com) domain, but add a language parameter, so that this should happen:

  • user requests www.mysite.cz -> gets redirected to www.mysite.com/cs
  • user requests www.mysite.hu -> gets redirected to www.mysite.com/hu

Is this possible with IIS URL Rewrite Module 2.0? If so, how do I do this?

Best Answer

OK, I'll answer myself. Here's how to do this:

Go to the website in IIS and add a new rewrite rule.
Set Match URL to .*
Add a Condition, where {HTTP_HOST} matches the pattern of ^www.mysite.cz$
Add an Action of Redirect type and Redirect URL http://www.mysite.com/cs