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. On-Page / Site Optimization
    4. Site wide 301 or canonical links.

    Site wide 301 or canonical links.

    On-Page / Site Optimization
    6 3 544
    • 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.
    • absoauto
      absoauto last edited by

      Hi guys, I'd like add code to my header file to specify www. as opposed to just http:// for the canonical links across my entire site. How can I do this? I'd like it to be site wide code that I can just add to my header.php file which is included across the site.

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

        Since the result you want is site wide, I would use a 301 redirect.

        It's more radical, but you won't depend on the right header file to be included in all pages (i.e. you will be able to use different files, if you ever need it - e.g. to set up a landing page or mini site with its own template).

        absoauto 2 Replies Last reply Reply Quote 1
        • absoauto
          absoauto @bemils last edited by

          Hi Lodovico, thanks for your reply. I am fine with that, but do you know how I'd have to write the 301 in my .htaccess file to 301 every http://xxxxx.com page to http://www.xxxxx.com ?

          1 Reply Last reply Reply Quote 0
          • absoauto
            absoauto @bemils last edited by

            Sorry I should have added I don't know the symbols to use to equate to any page starting with http:// should be fwd'ed to same page but http://www.

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

              Hi,

              I believe what you are looking for is

              Options +FollowSymLinks

              RewriteEngine on

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

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

              If I read the post correctly as adding a sitewide canonical in header.php would not work, unless you actually programmed a php statement that all it did was add www, but this would only be a backup, if I was unable to do 301 in my opinion

              Shane

              absoauto 1 Reply Last reply Reply Quote 1
              • absoauto
                absoauto @Jinx14678 last edited by

                Thanks Shane,

                That was exactly what I was looking for!

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                • Homepage canonical url with splash or not with splash? All other links are without but logo links with splash
                  advertisingcloud
                  advertisingcloud
                  0
                  3
                  59

                • 301 to canonical
                  ATP
                  ATP
                  0
                  6
                  165

                • Inbound Linking from your own sites
                  chrisdavieswebdesign
                  chrisdavieswebdesign
                  0
                  3
                  57

                • How to use canonical with mobile site to main site
                  giddygrafix
                  giddygrafix
                  0
                  13
                  10.6k

                • Canonical Link
                  partyrama
                  partyrama
                  0
                  4
                  149

                • Site Wide Link
                  makeshiftyy
                  makeshiftyy
                  0
                  2
                  598

                • 301 redirect link
                  AUSOM
                  AUSOM
                  0
                  4
                  583

                • Correct use of Canonical link vs 301 redirect
                  wedmonds
                  wedmonds
                  0
                  4
                  709

                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