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. Need Help writing 301 redirects in .htaccess file

    Need Help writing 301 redirects in .htaccess file

    Technical SEO Issues
    5 4 1.3k
    • 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.
    • WebsiteEditor
      WebsiteEditor last edited by

      SEOmoz tool shows me 2 errors for duplicate content pages (www.abc.com and www.abc.com/index.html). I believe, the solution to this is writing 301 redirects

      I need two 301 redirects

      1. abc.com  to  www.abc.com

      2. /index.html  to  /     (which is www.abc.com/index.html   to   www.abc.com)

      The code that I currently have is

      ...................................................

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

      Redirect 301 http://www.abc.com/index.html http://www.abc.com

      ......................................................

      but this does not redirect /index.html to abc.com. What is wrong here? Please help.

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

        I believe you need to have a wildcard at the end too; right now the expression is stopping searching at abc.com instead of looking past it. This is the one I use I think (going from memory) for a similar situation:

        RewriteCond %{HTTP_HOST} ^www.abc.com(.*)$ [NC]

        The (.*) means 'everything' as a wildcard

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

          I'm not a hundred percent on this-but am interested to see what everyone else thinks-So be patient:

          I think it should appear as follows:

          RewriteEngine On
          RewriteCond %{HTTP_HOST} !www.abc.com$[NC]
          RewriteRule ^(.*) $http//www.abc.com/$1 [L,R=301]

          or

          Redirect 301 abc.com/index.html http://www.abc.com

          Make sure you save your.TXT file with the correct name and to the correct location. I hope this helps. If I have this wrong anyone I would love to know the correct way myself.

          Thanks,

          Ally

          1 Reply Last reply Reply Quote 1
          • icecarats
            icecarats last edited by

            Oh yeah, sorry. The case I was thinking of was when you wanted to detect >everything< (e.g. abc.com/afjsk.htm) and redirect it. If you're only concerned with one case (index.html) Ally's solution is better. Remember that for individual cases you'd have to make an entry for each one (index.htm, index.php, default.htm) if those are becoming issues as well, which I doubt they would be in your case.

            1 Reply Last reply Reply Quote 0
            • Dr-Pete
              Dr-Pete last edited by

              I don't recall why, but I don't think you can use a full (absolute) path for the first part of a "Redirect 301" statement Could you try just:

              "Redirect 301 /index.html http://www.abc.com"

              Typically, the rewrite command (with flag of "R=301") is much more flexible. The "Redirect 301" syntax has some limitations - it's easier to use, but it only covers a few, simple situations.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              • I need help with redirecting chain to another page and 301, I don't understand on how to fix
                salem4e
                salem4e
                0
                3
                111

              • 301 redirects without .htaccess
                NancyVPS
                NancyVPS
                0
                5
                2.0k

              • A script to automatically write 301 redirect rules to htaccess?
                Klarke
                Klarke
                0
                4
                799

              • Do I need a 301 redirect on htaccess if Apache is already configured to serve?
                riplash
                riplash
                0
                6
                355

              • Help needed please with 301 redirects in htaccess file.
                petersommertravels
                petersommertravels
                0
                9
                2.3k

              • 301 Redirect Domain or 301 Redirect Domain + Interior Pages
                Room214
                Room214
                0
                7
                1.1k

              • I need some HTACCESS help (Magento)
                ShaMenz
                ShaMenz
                0
                6
                938

              • 301 Redirect Help
                hiphound
                hiphound
                0
                3
                891

              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