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. On-Page / Site Optimization
    4. 301 redirect (www.domain.com/index to www.domain.com)

    301 redirect (www.domain.com/index to www.domain.com)

    On-Page / Site Optimization
    12 3 16.8k
    • 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.
    • StalkerB
      StalkerB last edited by

      Probably the simplest way to redirect the non-www to the www is to put this in your .htaccess file

      RewriteEngine On Options +FollowSymLinks

      RewriteCond %{HTTP_HOST} ^example.com
      RewriteRule (.*) http://www.example.com/$1 [R=301,L]

      RewriteCond %{THE_REQUEST} ^./index.html
      RewriteRule ^(.
      )index.html$ http://www.example.com/$1 [R=301,L]

      For reference the .htaccess file goes in the root of your domain via whatever file transfer program you use and of course replace example.com with your domain 😉

      If you get stuck, let me know 🙂

      eyepaq 2 Replies Last reply Reply Quote 4
      • eyepaq
        eyepaq @StalkerB last edited by

        is the last part safe ? as far as the infinite loop things that some are afraid of..

        StalkerB Getz.pro eyepaq 5 Replies Last reply Reply Quote 1
        • StalkerB
          StalkerB @eyepaq last edited by

          The last part redirects index.html to /

          There would only be a loop if you redirected / to index.html

          99.9% sure this'll work for you 🙂 I'm using the exact code on a small site right now and it's working fine 🙂

          1 Reply Last reply Reply Quote 2
          • Getz.pro
            Getz.pro @eyepaq last edited by

            I agree with Barry, but watch out for that last snippet. I've got caught when hosting companies redirect on their side. So test before walking away for more coffee : )

            1 Reply Last reply Reply Quote 2
            • eyepaq
              eyepaq @eyepaq last edited by

              how it will behave if the redirect is not correct ? It will be visible ? (like a never-ending refresh of the main page)

              1 Reply Last reply Reply Quote 1
              • StalkerB
                StalkerB @eyepaq last edited by

                Yeah, if it doesn't work you'll probably be faced with a blank page or you may get a 500 server error or maybe a 310. It should be obvious pretty fast 🙂

                1 Reply Last reply Reply Quote 1
                • eyepaq
                  eyepaq @eyepaq last edited by

                  Thanks mate !

                  More then helpful.

                  1 Reply Last reply Reply Quote 0
                  • eyepaq
                    eyepaq @StalkerB last edited by

                    Can I use a code like this ? (i've added one entry for index.php as it looks like the site has both an index.html and an index.php)

                    Barry SmithJourneymanBarry Smith
                    Journeyman264 mozpoints
                    6 helpful answers
                    1 SEOmoz endorsed answers

                    | Selected AnswerHelpful Answer | Barry Smith, Head of SEO at Gaming Media Marketing | about 2 hours ago |

                    Probably the simplest way to redirect the non-www to the www is to put this in your .htaccess file

                    RewriteEngine On Options +FollowSymLinks

                    RewriteCond %{HTTP_HOST} ^example.com
                    RewriteRule (.*) http://www.example.com/$1 [R=301,L]

                    RewriteCond %{THE_REQUEST} ^./index.html
                    RewriteRule ^(.
                    )index.html$ http://www.example.com/$1 [R=301,L]

                    RewriteCond %{THE_REQUEST} ^./index.php
                    RewriteRule ^(.
                    )index.php$ http://www.example.com/$1 [R=301,L]

                    StalkerB eyepaq 3 Replies Last reply Reply Quote 0
                    • StalkerB
                      StalkerB @eyepaq last edited by

                      Hmm, maybe, I doubt the index.php is doing anything as if there's a index.html and index.php the .html takes precedence.

                      Check what's in the .php file, might be easier just to delete it.

                      1 Reply Last reply Reply Quote 1
                      • eyepaq
                        eyepaq @eyepaq last edited by

                        seomoz tool is showing duplicate pages for those 3. Each of the version has at least 1 internal and even external links.

                        all 3 respond in the browser with the same layout/page

                        1 Reply Last reply Reply Quote 0
                        • StalkerB
                          StalkerB @eyepaq last edited by

                          Well, I would recommend you alter the internal links to just point to the new '/' default, but in the meantime...

                          I would have thought your code would have worked, but every time I try it my site falls over. It might work for you though. Give it a try but test it straight away 🙂

                          I'll see if I can get a different version working on my test site for you if not 🙂

                          1 Reply Last reply Reply Quote 2
                          • 1 / 1
                          • First post
                            Last post
                          • What is the best way to block http://www.site.com/members/...
                            Taiger
                            Taiger
                            0
                            3
                            136

                          • Redirect www.domain to domain
                            Vizergy
                            Vizergy
                            1
                            6
                            104

                          • My report is showing duplicate titles.. for http://www.mysite.com/ & http://mysite.com
                            Fridaythe15th
                            Fridaythe15th
                            0
                            8
                            163

                          • Which is best for the website? Example blog that starts blog.domain.com or domain.com/blog? Thanks!
                            JonathanLeplang
                            JonathanLeplang
                            0
                            6
                            1.3k

                          • Redirecting web site URL to http://torontoairportlimoflatrate.com/ to http://www.torontoairportlimoflatrate.com
                            My-Favourite-Holiday-Cottages
                            My-Favourite-Holiday-Cottages
                            0
                            2
                            419

                          • Duplicate content http:// something .com and http:// something .com/
                            BlueprintMarketing
                            BlueprintMarketing
                            0
                            6
                            771

                          • Http://www.xxxx.com does not re-direct to http://xxx.com
                            DeptAgency
                            DeptAgency
                            0
                            10
                            46.5k

                          • Does a www.domain.com/# count as a link?
                            RyanKent
                            RyanKent
                            0
                            3
                            508

                          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

                          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