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. Do I need a 301 redirect on htaccess if Apache is already configured to serve?

    Do I need a 301 redirect on htaccess if Apache is already configured to serve?

    Technical SEO Issues
    6 2 355
    • 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.
    • Ocularis
      Ocularis last edited by

      Apache is set up to serve both www and non-www versions the same content. Do I still need to put a 301 redirect in the htaccess file?

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

        It's best practice to only serve a particular site one way or the other, either www or non-www, and only have one URL available for the homepage. This prevents any related duplicate content issues, and ensures you always get backlinks back to the right domain. I'd definitely recommend you add a rewrite rule to your .htaccess, using one of the following examples.

        removes www

        RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]

        RewriteRule ^(.*) http://yourdomain.com/$1 [L,R=301]

        adds www

        RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]

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

        Ocularis 1 Reply Last reply Reply Quote 1
        • Ocularis
          Ocularis @riplash last edited by

          But if it's Apache and set up to display the same content no matter which - how do I know which of the codes to add?

          riplash Ocularis 3 Replies Last reply Reply Quote 0
          • riplash
            riplash @Ocularis last edited by

            If you're launching the site fresh, just pick one and stick with it. If you've got an existing site, see which version Google returns in the SERPs, and use that.

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

              It's using www. in the SERPs. Does that mean I need to use the "## adds www"?

              Thanks!

              1 Reply Last reply Reply Quote 0
              • riplash
                riplash @Ocularis last edited by

                Yes, in that case, use the code that adds www. Then anyone who links to or attempts to visit the non-www, will be 301 redirected to the www version.

                1 Reply Last reply Reply Quote 1
                • 1 / 1
                • First post
                  Last post
                • 301 redirect syntax for htaccess
                  IOHanna
                  IOHanna
                  1
                  3
                  6.0k

                • Help creating a 301 redirect in my htaccess file
                  Felip3
                  Felip3
                  0
                  4
                  108

                • Redirect a 301 Redirect
                  RedCaffeine
                  RedCaffeine
                  0
                  5
                  98

                • Do I need both canonical meta tags AND 301 redirects?
                  Dr-Pete
                  Dr-Pete
                  0
                  4
                  1.1k

                • How long after google crawl do you need 301 redirects
                  TakeshiYoung
                  TakeshiYoung
                  0
                  4
                  1.3k

                • I have altered a url as it was too long. Do I need to do a 301 redirect for the old url?
                  TomRayner
                  TomRayner
                  0
                  4
                  181

                • To 301 redirect or not to 301 redirect? duplicate content problem www.domain.com and www.domain.com/en/
                  Chris-CA
                  Chris-CA
                  0
                  5
                  456

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

                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