6

What's the best way to do a 301 redirect from non-www 'somedomain.com' to 'www.somedomain.com' in IIS7.5?

Thank you

5

I would suggest that you install the URL ReWrite module for IIS 7 to do this for you. You would add a rule that looked soemthing like this

<rule name="Canonical Host Name" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" negate="true" pattern="somedomain\.com$" />
  </conditions>
  <action type="Redirect" url="http://www.somedomain.com{R:1}" redirectType="Permanent" />
</rule>

See this article for some hints and tips on URL ReWrite.

  • Sam, Is the condition required in this case since you've already wildcarded the URL? – Chris Anton Mar 31 '12 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.