Answered by:
url rewrite - add www

Question
-
trying to setup a simple rewrite rule to direct people going to domain.com to www.domain.com. The following is web.config:
<rewrite> <rules> <rule name="CanonicalHostNameRule1"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^www\.domain\.com$" negate="true" /> </conditions> <action type="Redirect" url="http://www.domain.com/{R:1}" /> </rule> </rules> </rewrite>
When tested it doesn't work, still gives a 404 when browsing to domain.com and internal server error when browsing to www.domain.com. Error logging gives the following:
HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the related configuration data for the page is invalid. Detailed Error Information: Module IIS Web Core Notification Unknown Handler Not yet determined Error Code 0x8007000d Config Error Configuration file '\\?\C:\DWASFiles\Sites\domain\VirtualDirectory0\site\wwwroot\web.config' does not contain a root <configuration> tag Config File \\?\C:\DWASFiles\Sites\domain\VirtualDirectory0\site\wwwroot\web.config
ADTU Enterprises
- Edited by adtuent Tuesday, April 2, 2013 7:18 AM
Tuesday, April 2, 2013 7:18 AM
Answers
-
Hi,
Try this:
<add input="{HTTP_HOST}" pattern="^domain\.com$" negate="true" />
Thanks,
QinDian Tang
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked as answer by Qin Dian Tang - MSFT Wednesday, April 10, 2013 2:17 AM
Wednesday, April 3, 2013 3:06 AM
All replies
-
Hi,
Try this:
<add input="{HTTP_HOST}" pattern="^domain\.com$" negate="true" />
Thanks,
QinDian Tang
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked as answer by Qin Dian Tang - MSFT Wednesday, April 10, 2013 2:17 AM
Wednesday, April 3, 2013 3:06 AM -
tried that, but same problem still persists.
ADTU Enterprises
Monday, April 22, 2013 5:51 AM -
Hi,
Here is the solution for having both domain names (domain.com and www.domain.com):
http://serverfault.com/questions/470888/azure-hosted-website-gives-404-error-when-domain-name-is-preceded-by-wwwQinDian Tang
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Monday, April 22, 2013 6:56 AM -
I know this is an old thread but it still shows up in search results..
here is how i would do this (and have done a www 301 many times before):
<rewrite> <rules> <rule name="www 301"> <match url="(.*)" ignoreCase="true" /> <conditions> <add input="{HTTP_HOST}" pattern="^domain\.com$" /> </conditions> <action type="Redirect" url="http://www.domain.com/{R:1}" redirectType="Permanent" /> </rule> </rules> </rewrite>
I always try to use descriptive names for my rules, it is not important but i feel better.
I always use the ignoreCase parameter
There is no need for the Negate parameter since we are targeting the url we want to redirect and not the url we dont want to redirect
the redirectType="permanent" is also better, that way crawlers will always know that the redirect is permanent and index your website accordingly.
- Proposed as answer by Siggi2000 Thursday, June 5, 2014 10:56 AM
Thursday, June 5, 2014 10:52 AM