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. Help writing a .htacess file with the correct 301 redirects

    Help writing a .htacess file with the correct 301 redirects

    Technical SEO Issues
    5 3 148
    • 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.
    • chriistaylor
      chriistaylor last edited by

      Hello

      I need help writing a .htaccess file that will do two things.

      URL match abc.com and www.abc.com to www.newabc.com

      except one subdomain was also changed www.abc.com/blog is now  www.newabc.com/newblog

      everything after blog matches.

      Any help would greatly be appreciated.

      Thanks

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

        The normal rule to achieve this is:

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

        For the blog issue you may consider adding an htaccess file in the blog folder and put

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

        or maybe you can achieve that by adding the line:

        RewriteRule ^blog(.*) http://www.newabc.com/newblog$1 [R=301,L]

        However in this second case you'll have a double redirect: the first which redirect blog to new blog and then the non www to www.

        1 Reply Last reply Reply Quote 2
        • Aleyda
          Aleyda last edited by

          Hi Chris,

          To redirect your old domain to the new domain with the same path for all the URLs except a specific directory, for example: /blog/ that is going to be renamed /newblog/ in your new domain, it will be:

          <ifmodule mod_rewrite.c="">RewriteEngine On</ifmodule>

          RewriteCond %{REQUEST_URI} ^/blog/(.) [NC]
          RewriteRule ^blog/(.
          )$ http://www.newabc.com/newblog/$1 [R=301,L]

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

          Thanks,

          Aleyda

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

            Aleyda and Mememax

            Thanks very much for the help. Aleyda your answer worked perfectly.

            Thanks again!

            Chris

            mememax 1 Reply Last reply Reply Quote 0
            • mememax
              mememax @chriistaylor last edited by

              yes ALeyda answer was more concrete for sure 🙂 Glad to have been of help however 🙂

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              • Where to put 301 redirects in my Wordpress htaccess file?
                Benspain
                Benspain
                0
                3
                34

              • HTacess 301 redirect with special characters
                TheeDigital
                TheeDigital
                0
                3
                909

              • Redirect a 301 Redirect
                RedCaffeine
                RedCaffeine
                0
                5
                98

              • 301 Redirect Help
                dhidalgo1
                dhidalgo1
                1
                3
                115

              • Help with 301 redirect code
                Aleyda
                Aleyda
                0
                9
                191

              • 301 Redirect on a PDF, DOCX files?
                KevinBudzynski
                KevinBudzynski
                0
                4
                16.2k

              • 301 Redirect NOT Working as Expected - HELP!
                hiphound
                hiphound
                0
                5
                1.1k

              • 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