Question

I'm on IIS 7 and trying to redirect a URL for example www.domainname.co.uk/something to www.domain.co.uk but it doesn't seem to be hitting it in the web.config.

<redirect url="domain.co.uk/something/" to="http://www.newdomain.co.uk"/>    

Any ideas why it's not hitting?

Was it helpful?

Solution

IIS uses <httpRedirect> with a variety of child elements to achieve the required effect, if necessary.

It's documented here: http://www.iis.net/configreference/system.webserver/httpredirect

In the filesystem directory corresponding to the /something/ path for your domain.co.uk website, add a web.config file with this:

<configuration>
   <system.webServer>
      <httpRedirect enabled="true" destination="http://www.newdomain.co.uk" exactDestination="true" httpResponseStatus="Permanent" />
   </system.webServer>
</configuration>

Note that your domain.co.uk/something/ and newdomain.co.uk/ directories cannot share this web.config otherwise it will cause an infinite redirection loop. If you want canonical domain names then I recommend using the URL Rewrite module instead, which provides redirection abilities in addition to URL rewriting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top