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. Non-www to www code not working in htaccess

    Non-www to www code not working in htaccess

    Technical SEO Issues
    4 2 667
    • 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.
    • Caleone
      Caleone last edited by

      I use the same rewrite code on every site to consolidate the non-www and www versions.

      All sites in Joomla, linux hosting. Code is as follows:

      RewriteEngine On

      rewritecond %{http_host} ^site.com/

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

      Immediately following this code, I also rewrite /index.php to /.

      Thing is, I can get index.php to rewrite correctly but the non-www won't rewrite to www.

      I use the same code on every site but for some reason it's not working here.

      Are there common issues that interfere with rewriting a non-www to www in htaccess that could be interfering with the code I'm using above?

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

        An alternative that I've had working on Joomla sites is:

        #add www

        RewriteCond %{HTTP_HOST} ^site.com$ [NC]

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

        RewriteCond %{THE_REQUEST} !^POST

        #remove /index.php and ensure admin works okay

        RewriteCond %{REQUEST_URI} !^/administrator

        RewriteCond %{THE_REQUEST} ^.*/index.php\ HTTP/

        RewriteRule ^(.*)index.php$ /$1 [R=301,L]

        One final thing, have you tried using

        Options +FollowSymLinks

        Caleone 1 Reply Last reply Reply Quote 1
        • Caleone
          Caleone @JaspalX last edited by

          Hi Jassy,

          Thanks for your response. I was already using +followsymlinks.

          Just tried your code and it did the trick!

          Thanks a bunch 🙂

          JaspalX 1 Reply Last reply Reply Quote 0
          • JaspalX
            JaspalX @Caleone last edited by

            You're very welcome 🙂

            BTW, I use SH404SEF with Joomla too, which is pretty good, but is a paid-for product.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            • SSL, www issue. Should we buy WWW license or just add redirect from www to non-www site?
              Ryan_V
              Ryan_V
              0
              8
              141

            • WWW to Non-WWW = Less Indexing?
              BradyDCallahan
              BradyDCallahan
              0
              3
              178

            • Redirecting non-www to www
              Christy-Correll
              Christy-Correll
              0
              6
              466

            • Difference between www and non-www site
              Cyrus-Shepard
              Cyrus-Shepard
              0
              6
              7.8k

            • Www to non www
              seoug_2005
              seoug_2005
              0
              9
              543

            • Www vs non-www
              kylesuss
              kylesuss
              0
              6
              808

            • Www vs non www
              Marcus_Miller
              Marcus_Miller
              0
              5
              1.2k

            • How do I redirect non-www to www in IIS?
              tylerfraser
              tylerfraser
              0
              2
              986

            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