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. White Hat / Black Hat SEO
    4. What is the difference between the two rewrite rules in htaccess?

    What is the difference between the two rewrite rules in htaccess?

    White Hat / Black Hat SEO
    5 3 175
    • 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.
    • esiow2013
      esiow2013 last edited by

      Force www. prefix in URLs and redirect non-www to www

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

      Force www. prefix in URLs and redirect non-www to www - 2nd option

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

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

        Hi, as mentioned in the other answer I gave here: http://moz.com/community/q/where-is-the-rule-here-that-force-www-in-urls#reply_202351

        the first checks for non-inclusion of the www in the URL (the !^www checks if www is not included at the start of the URL being tested), the second checks for a URL that starts with just the domain.

        Peter

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

          So in theory they are identical?

          Just different ways of achieving the same result

          crackingmedia 1 Reply Last reply Reply Quote 0
          • crackingmedia
            crackingmedia @Burto last edited by

            Yes, the result is identical.

            Peter

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

              Thanks Peter!

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              • Different site behind the flag
                gfiorelli1
                gfiorelli1
                0
                3
                92

              • NoFollow Rules, Inconsistent?
                MarieHaynes
                MarieHaynes
                0
                6
                177

              • What is the difference between using .htaccess file and httpd.conf in implementing thousands of 301 redirections?
                esiow2013
                esiow2013
                0
                5
                1.1k

              • I'm planning to put 5000+ 301 redirect rules in .htaccess. Is that ok?
                esiow2013
                esiow2013
                0
                4
                263

              • Where is the rule here to remove trailing slashes in URLs?
                Devanur-Rafi
                Devanur-Rafi
                0
                6
                161

              • Same content, different target area SEO
                0
                1
                216

              • Same template site same products but different content?
                Mark_Jay_Apsey_Jr.
                Mark_Jay_Apsey_Jr.
                0
                2
                590

              • Difference between Syndication, Autoblogging, and Article Marketing
                summitseo
                summitseo
                0
                3
                1.7k

              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