#1
  1. Contributing User
    SEO Chat Discoverer (100 - 499 posts)

    Join Date
    Sep 2016
    Location
    United Kingdom
    Posts
    259
    Rep Power
    253

    non-www to www. redirect


    Hi, could someone please supply me the could for a SEO safe non-www, to www redirect (the websites on a windows server, so webconfig code) ??

    This is what I've done, will this do the job ?


    File one:

    Code:
    <configuration>
        <system.webServer>
            <rewrite>
                <rewriteMaps configSource="rewritemaps.config"></rewriteMaps>
                <rules>
                    <rule name="Redirect rule1 for Redirects">
                    <match url=".*" />
                    <conditions>
                        <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
                    </conditions>
                    <action type="Redirect" url="{C:1}" appendQueryString="false" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    File two:
    Code:
    <rewriteMaps>
        <rewriteMap name="Redirects">
            <add key="/oldurl" value="/newurl" />
            <add key="/oldurl2" value="/newurl2" />
        </rewriteMap>
    </rewriteMaps>
    Last edited by matt1966; Oct 15th, 2017 at 08:32 AM.
  2. #2
  3. SeoRaptor
    SEO Chat Adventurer (500 - 999 posts)

    Join Date
    Mar 2016
    Location
    France, Saint-Etienne
    Posts
    997
    Rep Power
    1703
    Hi Matt1966,

    I'm no Windows server user so I can not help you directly but there is this ressource on microsoft website that could help you out.

    https://docs.microsoft.com/en-us/iis...-iis-webconfig

    I think Chedders might be able to help you out but I know he has little time lately.
    Owner of Bennetonable - "My opinions are my own - Feel free to disagree & think above the fold."
    Need a quick analysis > Free SEO grader Beta
  4. #3
  5. No Profile Picture
    Moderator
    SEO Chat Good Citizen (1000 - 1499 posts)

    Join Date
    Sep 2016
    Location
    USA
    Posts
    1,414
    Rep Power
    2532
    Hey mate, I think this is what you want... This should fix you right up.....

    Code:
    <rewrite>
      <rules>
        <rule name="Redirect to www" stopProcessing="true">
          <match url="(.*)" />
          <conditions trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="^domain.com$" />
          </conditions>
          <action type="Redirect"  url="{MapProtocol:{HTTPS}}://www.domain.com/{R:1}" />
        </rule>
      </rules>
      <rewriteMaps>
        <rewriteMap name="MapProtocol">
          <add key="on" value="https" />
          <add key="off" value="http" />
        </rewriteMap>
      </rewriteMaps>
    </rewrite>
  6. #4
  7. Contributing User
    SEO Chat Discoverer (100 - 499 posts)

    Join Date
    Sep 2016
    Location
    United Kingdom
    Posts
    259
    Rep Power
    253
    Originally Posted by KnowOneSpecial
    Hey mate, I think this is what you want... This should fix you right up.....

    Code:
    <rewrite>
      <rules>
        <rule name="Redirect to www" stopProcessing="true">
          <match url="(.*)" />
          <conditions trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="^domain.com$" />
          </conditions>
          <action type="Redirect"  url="{MapProtocol:{HTTPS}}://www.domain.com/{R:1}" />
        </rule>
      </rules>
      <rewriteMaps>
        <rewriteMap name="MapProtocol">
          <add key="on" value="https" />
          <add key="off" value="http" />
        </rewriteMap>
      </rewriteMaps>
    </rewrite>
    Thanks buddy. Am I right in thinking this will automatically 301 redirect all non-www versions?
  8. #5
  9. Contributing User
    SEO Chat Discoverer (100 - 499 posts)

    Join Date
    Sep 2016
    Location
    United Kingdom
    Posts
    259
    Rep Power
    253
    Originally Posted by Pierre Benneton
    this ressource on microsoft website that could help you out.

    https://docs.microsoft.com/en-us/iis...-iis-webconfig
    Thanks man, that resource seems pretty useful!
  10. #6
  11. No Profile Picture
    Moderator
    SEO Chat Good Citizen (1000 - 1499 posts)

    Join Date
    Sep 2016
    Location
    USA
    Posts
    1,414
    Rep Power
    2532
    Originally Posted by 1966
    Thanks buddy. Am I right in thinking this will automatically 301 redirect all non-www versions?
    Yep, sure will....

Similar Threads

  1. SEO - Duplicate Title in Google Webmaster after Internal Redirect(Not 301 Redirect)
    By awsway in forum New User SEO Questions and Answers
    Replies: 1
    Last Post: Dec 7th, 2015, 03:54 PM
  2. 301 redirect
    By bingoblogger in forum Web Design, Coding and Programming
    Replies: 6
    Last Post: Oct 23rd, 2008, 10:30 AM
  3. 301 redirect or 302 redirect for google
    By rajput_jitendra in forum Google Optimization
    Replies: 10
    Last Post: Jun 6th, 2006, 04:43 AM
  4. 301 redirect:.htaccess and php redirect?
    By lilyfok in forum Google Optimization
    Replies: 3
    Last Post: May 3rd, 2006, 10:46 AM

IMN logo majestic logo threadwatch logo seochat tools logo