Iis – Domain redirection to specific page in IIS

iisredirectwindows-server-2012

I have a website on IIS set to domain1.com. I also have a domain called domain2.com that is redirecting to domain1.com. I currently have this set up in the domain1.com bindings. I need to change this to where domain2.com is redirected to domain1.com/blog

Would I do this through the web.config file or is there another way?

Best Answer

Another option is to do it using the appcmd.exe command, using command prompt.
The above commands should do the job.
This commands are also useful to create any kind of redirection.
The url rewrite module is a requirement. It has to be installed on your IIS.
This commands are running without problems on my Windows Server 2012 machine.

C:\Windows\System32\inetsrv\appcmd.exe set config "%domain%" -section:system.webServer/rewrite/rules /+"[name='Redirect_To_www',enabled='True']" >> output.out
C:\Windows\System32\inetsrv\appcmd.exe set config "%domain%" -section:system.webServer/rewrite/rules -[name='Redirect_To_www'].match.url:"(.*)" >> output.out
C:\Windows\System32\inetsrv\appcmd.exe set config "%domain%" -section:system.webServer/rewrite/rules -[name='Redirect_To_www'].match.ignoreCase:true >> output.out

C:\Windows\System32\inetsrv\appcmd.exe set config "%domain%" -section:system.webServer/rewrite/rules -[name='Redirect_To_www'].conditions.logicalGrouping:"MatchAny" >> output.out
C:\Windows\System32\inetsrv\appcmd.exe set config "%domain%" -section:system.webServer/rewrite/rules /+"[name='Redirect_To_www'].conditions.[input='{HTTP_HOST}',pattern='^www\.([.a-zA-Z0-9\-]+)$',negate='true']" >> output.out

C:\Windows\System32\inetsrv\appcmd.exe set config "%domain%" -section:system.webServer/rewrite/rules -[name='Redirect_To_www'].action.type:"Redirect" >> output.out
C:\Windows\System32\inetsrv\appcmd.exe set config "%domain%" -section:system.webServer/rewrite/rules -[name='Redirect_To_www'].action.url:"http://www.{HTTP_HOST}/{R:0}" >> output.out
C:\Windows\System32\inetsrv\appcmd.exe set config "%domain%" -section:system.webServer/rewrite/rules -[name='Redirect_To_www'].action.appendQueryString:true >> output.out
C:\Windows\System32\inetsrv\appcmd.exe set config "%domain%" -section:system.webServer/rewrite/rules -[name='Redirect_To_www'].action.redirectType:"Permanent" >> output.out


Hope that helps.