The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Technical SEO Issues
    4. How do I redirect non www pages to www on a windows server?

    How do I redirect non www pages to www on a windows server?

    Technical SEO Issues
    6 2 4.1k
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • ArjunRajkumar
      ArjunRajkumar last edited by

      As the .htaccess file cannot be worked on, I added this php code 301 redirect if the URL does not contain a www on all the pages (small website - 10 pages) :

      header( "HTTP/1.1 301 Moved Permanently" );

      header( "Location: $location" );

      I want to know if this is ok for SEO? Has anyone done this on a windows server? Or if you have any better methods, it would be great if you can share.

      Please help.

      Thanks.

      1 Reply Last reply Reply Quote 0
      • AlanMosley
        AlanMosley last edited by

        go to yout iis server control panel look for url rewriting, if it is not there install it using web platform installer.

        then it is a simple ass picking it from a list.

        You can also do it in code, using a class inherting the httpmodule this intercepts request before reaching website.

        But the easiest way is using the URL rewriting as i suggested.

        If tyou dont have access. plonk this in your web.config, change from mydomain.com.au to your own domain

        <system.webserver>       
                <rewrite><rules><rule name="CanonicalHostNameRule"><match url="(.*)"><conditions><add input="{HTTP_HOST}" pattern="^mydomian.com.au$" negate="true"></add></conditions>
                            <action type="Redirect" url="<a href=" http:="" mydomain.com.au="" {r:1"="">http://mydomain.com.au/{R:1}" />
                       </action></match></rule>
                        <rule name="LowerCaseRule" stopprocessing="true"><match url="[A-Z]" ignorecase="false"><action type="Redirect" url="{ToLower:{URL}}"><conditions><add input="{URL}" pattern="WebResource.axd" negate="true"><add input="{URL}" pattern="Scripts" negate="true"><add input="{URL}" pattern="Content" negate="true"></add></add></add></conditions></action></match></rule></rules></rewrite>
           </system.webserver>

        ArjunRajkumar 1 Reply Last reply Reply Quote 2
        • ArjunRajkumar
          ArjunRajkumar @AlanMosley last edited by

          Thanks Alan. It's very clear what to do now. I don't have access but will speak to the people who do have access and see if it can done the way you mentioned using URL redirect from the server control panel itself.

          Thank you!

          Arjun

          AlanMosley ArjunRajkumar 3 Replies Last reply Reply Quote 0
          • AlanMosley
            AlanMosley @ArjunRajkumar last edited by

            Yes the control panel will put the code in the web.config for you, or uyou can put it in manualy.

            The code above has 2 riles in it, to fix domain name, the other to make sure url is lower case

            1 Reply Last reply Reply Quote 0
            • ArjunRajkumar
              ArjunRajkumar @ArjunRajkumar last edited by

              Hi Alan, They are not able to do it via the control panel - and there is no way that they will share the password for us to do it. Therefore I think we have to do it manually. Can you please check if this code is correct. I have replaced my domain.com.au to www.oberoihotels.com (as an example) in 2 places : Changed "^mydomian.com.au$" to "^oberoihotels.com$" and changed url="http://mydomain.com.au/{R:1to url="http://oberoihotels.com/{R:1 Is this correct? Therefore the new code to add to the web.config file :<system.webserver><rewrite><rules><rule name="CanonicalHostNameRule"><match url="(.*)"><conditions><add input="{HTTP_HOST}" pattern="^oberoihotels.com$" negate="true"></add></conditions><action type="Redirect" url="http://oberoihotels.com/{R:1}"></action></match></rule><rule name="LowerCaseRule" stopprocessing="true"><match url="[A-Z]" ignorecase="false"><action type="Redirect" url="{ToLower:{URL}}"><conditions><add input="{URL}" pattern="WebResource.axd" negate="true"><add input="{URL}" pattern="Scripts" negate="true"><add input="{URL}" pattern="Content" negate="true"></add></add></add></conditions></action></match></rule></rules></rewrite></system.webserver>

              1 Reply Last reply Reply Quote 0
              • AlanMosley
                AlanMosley @ArjunRajkumar last edited by

                If you want to go to the www version, then you want

                "^www.oberoihotels.com$"

                and

                {R:1to url="http://www.oberoihotels.com/{R:1

                look for this tag

                you dont want to have 2, if you already have one add the code to that one.

                let me know if you have anny problems

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                • Resolving 301 Redirect Chains from Different URL Versions (http, https, www, non-www)
                  0
                  1
                  38

                • Worth redirecting non-www to www due to higher page authority with www?
                  GastonRiera
                  GastonRiera
                  0
                  4
                  276

                • Duplicate Page Content for www and non-www. Help!
                  Andy.Drinkwater
                  Andy.Drinkwater
                  0
                  7
                  486

                • If I want clean up my URLs and take the "www.site.com/page.html" and make it "www.site.com/page" do I need a redirect?
                  Booj
                  Booj
                  0
                  4
                  113

                • How to redirect index.htm (IIS server, windows hosting) to index.php (Apache server, Linux Hosting) ?
                  Cyrus-Shepard
                  Cyrus-Shepard
                  0
                  8
                  4.1k

                • Redirect non www. domain to WWW. domain for established website?
                  malecce
                  malecce
                  0
                  2
                  207

                • Delete 301 redirected pages from server after redirect is in place?
                  RuthBurrReedy
                  RuthBurrReedy
                  0
                  5
                  4.0k

                • Non-www home page indexed, but www for rest of site
                  AlanBleiweiss
                  AlanBleiweiss
                  0
                  7
                  755

                Get started with Moz Pro!

                Unlock the power of advanced SEO tools and data-driven insights.

                Start my free trial
                Products
                • Moz Pro
                • Moz Local
                • Moz API
                • Moz Data
                • STAT
                • Product Updates
                Moz Solutions
                • SMB Solutions
                • Agency Solutions
                • Enterprise Solutions
                • Digital Marketers
                Free SEO Tools
                • Domain Authority Checker
                • Link Explorer
                • Keyword Explorer
                • Competitive Research
                • Brand Authority Checker
                • Local Citation Checker
                • MozBar Extension
                • MozCast
                Resources
                • Blog
                • SEO Learning Center
                • Help Hub
                • Beginner's Guide to SEO
                • How-to Guides
                • Moz Academy
                • API Docs
                About Moz
                • About
                • Team
                • Careers
                • Contact
                Why Moz
                • Case Studies
                • Testimonials
                Get Involved
                • Become an Affiliate
                • MozCon
                • Webinars
                • Practical Marketer Series
                • MozPod
                Connect with us

                Contact the Help team

                Join our newsletter
                Moz logo
                © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
                • Accessibility
                • Terms of Use
                • Privacy