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. Web Design
    4. What is the code to 301 http to www in htaccess file on unix server

    What is the code to 301 http to www in htaccess file on unix server

    Web Design
    3 3 150
    • 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.
    • Ron10
      Ron10 last edited by

      i want to 301 my http home page  to www on a linux server and all my other redirects are set up similar to  this in my htaccess file:

      redirect 301 /example-page.html http://www.example-page.html

      how do I 301 redirect:

      http://example.com to http://www.example.com

      I've tried all kinds of code recommended for an htaccess file on a linux server  and nothing seems to work.

      Thanks for the help mozzers!

      Ron

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

        Hi Ron,

        You will need to use URL rewrite and the following code:

        RewriteEngine On

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

        That will redirect any page/file on example.com/file to www.example.com/file with a 301 redirect.

        Hope that helps!

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

          1st works fine for me....

          Redirect 301 /tags/xp/ http://www.test.com/tags/windows-xp/

          if it is not working there must be some other problem!

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          • Best Practices-Optimize Theme Before Coding or After Coding?
            TucsonAZWebDesign
            TucsonAZWebDesign
            0
            2
            272

          • Should I do multiple 301 redirects?
            nhhernandez
            nhhernandez
            0
            2
            987

          • What are the downsides and/or challenges to putting page paths (www.example.com/pagepath) on a different server?
            HiveDigitalInc
            HiveDigitalInc
            0
            2
            37

          • Duplicate Content Home Page http Status Code Query
            AlexMcKee
            AlexMcKee
            0
            3
            383

          • Question #2: All of my INTERNAL links in OSE are being indexed from http://www.e.com/default.asp, and all my EXTERNAL links are linked to http://www.e.com/ am I getting a fraction of the link juice because of that?????
            RobertFisher
            RobertFisher
            0
            2
            157

          • SEO and Server Connectivity....
            RobertChapman
            RobertChapman
            0
            4
            488

          • Is there a limit for 301 redirection in htaccess file?
            Vizergy
            Vizergy
            0
            3
            5.3k

          • SEOMoz crawl report shows a duplicate content and duplicate title for these two url's http://freightmonster.com/ and http://freightmonster.com/index.html. How do I fix this?
            Smith-Digital
            Smith-Digital
            1
            3
            610

          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