Question

I have created code to redirect for non www to www, /index.html to "/", 404 to custom page, I am using IIS server and putting this code in web.config file, have a look, its working fine. But I want to know is it good for SEO ? Or It need any modification ?

Thanx

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <rewrite>
      <rules>
        <rule name="CanonicalHostNameRule1" stopProcessing="true">
          <match url="index\.html(?:l)?" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="example\.com.au$" />
          </conditions>
          <action type="Redirect" url="http://www.example.com.au/" />
        </rule>
        <rule name="CanonicalHostNameRule2" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^example\.com.au$" />
          </conditions>
          <action type="Redirect" url="http://www.example.com.au/{R:1}" />
        </rule>
      </rules>
    </rewrite>
    <httpErrors errorMode="Custom" existingResponse="Replace">
      <remove statusCode="404" />
      <error statusCode="404" responseMode="ExecuteURL" path="/404error.html" />
    </httpErrors>
  </system.webServer>
</configuration>
Was it helpful?

Solution

Your rules look fine. In general, the idea with making your URLs cannonical is to direct all the link juice to a single cannonical address. In the eyes of Google and such, www.mydomain.com and mydomain.com are two different URLs. Same goes for mydomain.com/ and mydomain.com/imndex.html. The only thing I would add to your rules is a statusCode of 302. This will tell both Google and client`s browsers that you would like them to reffer to the target URL from now on. This way Google will sum all link juice to the target and also clients browsers will not need to be re-redirected with each request.

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