Wednesday, August 23, 2017

Redirecting non-www to www URLS asp.net

Most domains are set up with an @ record that points their domain in its purest form (e.g. domain.com) to their web server's IP address and a CNAME record that points www.domain.com to the @ record. Then both domain.com and www.domain.com are added as bindings for the site in IIS. This is useful for those visitors that type a web address without the www prefix. It will ensure that the request is routed to the correct server. As I have already mentioned, this results in two valid URLs for the same content, and while that issue can be taken care of with the use of rel="canonical", you can also use an HTTP redirect if your IIS server has URL Rewrite installed. You don't even need access to the web server to set up a rewrite rule. You can do it in your site's web.config.

Details: https://www.mikesdotnetting.com/article/290/seo-for-asp-net-web-sites-urls 

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Redirect non-www traffic to www" stopProcessing="true">
        <match url=".*" ignoreCase="true" />
        <conditions>
          <add input="{HTTP_HOST}" pattern="^mikesdotnetting.com$" />
        </conditions>
        <action type="Redirect" url="http://www.mikesdotnetting.com/{R:0}" redirectType="Permanent" />
      </rule>
    </rules>
  </rewrite>
</system.webServer>

No comments:

Post a Comment