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. 301 domain name URL variants for canonicalization question in htaccess?

    301 domain name URL variants for canonicalization question in htaccess?

    White Hat / Black Hat SEO
    2 2 498
    • 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

      #1

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

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

      What I want to do here is to redirect URLs that have omitted the “www.” prefix to the full “www.xyz.com” home page URL. That means the home page URL http://xyz.com will not resolve on its own, but instead will redirect to http://www.xyz.com (without trailing slash).

      #2

      RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index).(html|php|htm)\ HTTP/ [NC]

      RewriteRule ^(([^/]+/)*)(default|main|index).(html|php|htm)$ http://www.xyz.com/$1 [L,R=301]

      What I want to do here is to ensure that any home page URL that includes several versions of explicit page name references, such as default.htm or index.html, will be redirected to the canonical home page URL, http://www.xyz.com (without trailing slash).

      Are the rewrite rules correct? Thanks in advance!

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

        I've tested both and the logic looks fine.

        However, as always with .htaccess changes, I'd recommend testing to verify this has been set up properly once you roll these out (easy enough with a quick ping / page load).

        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        • Deleting 301 Redirect URLs from the CMS
          KevinBudzynski
          KevinBudzynski
          0
          4
          80

        • URL for Photography Domain
          ViviCa1
          ViviCa1
          0
          3
          423

        • Vanity URLs Canonicalization
          garfield_disliker
          garfield_disliker
          1
          7
          515

        • How to 301 redirect from old domain and their pages to new domain and pages?
          andzon
          andzon
          0
          9
          5.5k

        • Domain name for seo
          ZDAdmin
          ZDAdmin
          0
          3
          162

        • What is the difference between Redirect 301 and RedirectMatch 301 in .htaccess?
          Devanur-Rafi
          Devanur-Rafi
          0
          2
          12.9k

        • Keyword Named Domains
          ColinWhite
          ColinWhite
          0
          5
          230

        • Keyword Rich Domain Names
          StalkerB
          StalkerB
          0
          7
          1.3k

        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