Configure IIS to permanently (301) redirect to www domain address
April 1st, 2013Here’s a tiny web.config file for making sure a website is configured to redirect (using 301 status code) to another website, often useful when a redirection to the www.domainname.com version is necessary. (Important for SEO)
Make sure the Windows feauture HTTP Redirection is activated on the server.
1 2 3 4 5 6 | <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <httpRedirect enabled="true" destination="http://www.yourdomainhere.com" exactDestination="true" httpResponseStatus="Permanent" /> </system.webServer> </configuration> |
If you need to pass the querystring forward to the target destination, you need to add $Q after the destination.
To include both path and querystring parameters, change the httpRedirect to the following:
1 | <httpRedirect enabled="true" destination="http://www.yourdomainhere.com$V$Q" exactDestination="true" httpResponseStatus="Permanent" /> |