undefined
Skip to content
Moz logo Menu open Menu close
  • Products
    • Moz Pro
    • Moz Pro Home
    • Moz Local
    • Moz Local Home
    • STAT
    • Moz API
    • Moz API Home
    • Compare SEO Products
    • Moz Data
  • Free SEO Tools
    • Domain Analysis
    • Keyword Explorer
    • Link Explorer
    • Competitive Research
    • MozBar
    • More Free SEO Tools
  • Learn SEO
    • Beginner's Guide to SEO
    • SEO Learning Center
    • Moz Academy
    • SEO Q&A
    • Webinars, Whitepapers, & Guides
  • Blog
  • Why Moz
    • Agency Solutions
    • Enterprise Solutions
    • Small Business Solutions
    • Case Studies
    • The Moz Story
    • New Releases
  • Log in
  • Log out
  • Products
    • Moz Pro

      Your all-in-one suite of SEO essentials.

    • Moz Local

      Raise your local SEO visibility with complete local SEO management.

    • STAT

      SERP tracking and analytics for enterprise SEO experts.

    • Moz API

      Power your SEO with our index of over 44 trillion links.

    • Compare SEO Products

      See which Moz SEO solution best meets your business needs.

    • Moz Data

      Power your SEO strategy & AI models with custom data solutions.

    NEW Keyword Suggestions by Topic
    Moz Pro

    NEW Keyword Suggestions by Topic

    Learn more
  • Free SEO Tools
    • Domain Analysis

      Get top competitive SEO metrics like DA, top pages and more.

    • Keyword Explorer

      Find traffic-driving keywords with our 1.25 billion+ keyword index.

    • Link Explorer

      Explore over 40 trillion links for powerful backlink data.

    • Competitive Research

      Uncover valuable insights on your organic search competitors.

    • MozBar

      See top SEO metrics for free as you browse the web.

    • More Free SEO Tools

      Explore all the free SEO tools Moz has to offer.

    NEW Keyword Suggestions by Topic
    Moz Pro

    NEW Keyword Suggestions by Topic

    Learn more
  • Learn SEO
    • Beginner's Guide to SEO

      The #1 most popular introduction to SEO, trusted by millions.

    • SEO Learning Center

      Broaden your knowledge with SEO resources for all skill levels.

    • On-Demand Webinars

      Learn modern SEO best practices from industry experts.

    • How-To Guides

      Step-by-step guides to search success from the authority on SEO.

    • Moz Academy

      Upskill and get certified with on-demand courses & certifications.

    • SEO Q&A

      Insights & discussions from an SEO community of 500,000+.

    Unlock flexible pricing & new endpoints
    Moz API

    Unlock flexible pricing & new endpoints

    Find your plan
  • Blog
  • Why Moz
    • Small Business Solutions

      Uncover insights to make smarter marketing decisions in less time.

    • Agency Solutions

      Earn & keep valuable clients with unparalleled data & insights.

    • Enterprise Solutions

      Gain a competitive edge in the ever-changing world of search.

    • The Moz Story

      Moz was the first & remains the most trusted SEO company.

    • Case Studies

      Explore how Moz drives ROI with a proven track record of success.

    • New Releases

      Get the scoop on the latest and greatest from Moz.

    Surface actionable competitive intel
    New Feature

    Surface actionable competitive intel

    Learn More
  • Log in
    • Moz Pro
    • Moz Local
    • Moz Local Dashboard
    • Moz API
    • Moz API Dashboard
    • Moz Academy
  • Avatar
    • Moz Home
    • Notifications
    • Account & Billing
    • Manage Users
    • Community Profile
    • My Q&A
    • My Videos
    • Log Out

The Moz Q&A Forum

  • Forum
  • Questions
  • Users
  • Ask the Community

Welcome to the Q&A Forum

Browse the forum for helpful insights and fresh discussions about all things SEO.

  1. Home
  2. SEO Tactics
  3. Technical SEO
  4. I need help with a PHP canonical URL tags

Moz Q&A is closed.

After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.

I need help with a PHP canonical URL tags

Technical SEO
4
4
4.5k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as question
Log in to reply
This topic has been deleted. Only users with question management privileges can see it.
  • lnietob
    lnietob last edited by Sep 13, 2012, 9:00 AM

    I found a little difficult for me to do a canonical tag in my PHP.

    On-Page Report Card

    We check to make sure that IF you use canonical URL tags, it points to the right page. If the canonical tag points to a different URL, engines will not count this page as the reference resource and thus, it won't have an opportunity to rank. If you've not made this page the rel=canonical target, change the reference to this URL. NOTE: For pages not employing canonical URL tags, this factor does not apply.

    I don't know how to tidy my PHP

    Any suggestion.

    1 Reply Last reply Reply Quote 0
    • ACann
      ACann @Jinx14678 last edited by Jul 18, 2013, 2:00 PM Jul 18, 2013, 2:00 PM

      Thanks Shane,

      That was very simple and to the point.  I am doing SEO on a php site where there's a header and a footer and I didin't know how to add the canoical tag to the header correctly and the On page.  Thanks again.

      Benny

      1 Reply Last reply Reply Quote 0
      • topic:timeago_earlier,10 months
      • Dr-Pete
        Dr-Pete Staff last edited by Sep 13, 2012, 5:40 PM Sep 13, 2012, 5:40 PM

        Is this a CMS, or are you trying to make the canonical only impact certain pages or conditions? The canonical tag is just an HTML tag, in the header. It doesn't really need special code, unless the target of the canonical has to be created dynamically. Unfortunately, then the solution depends entirely on your implementation (it's not one-sized-fits-all across all PHP sites).

        If you could describe the structure of the site a bit (example URLs and how they're created) without revealing the site, that could help us pin it down.

        1 Reply Last reply Reply Quote 0
        • Jinx14678
          Jinx14678 last edited by Sep 13, 2012, 9:04 AM Sep 13, 2012, 9:04 AM

          Hi,

          In my site, I use a php expression - as such -

          header.php -

          On page -

          $canonical = "http://www.domain.com";

          Here is a recent Blog Post if the above code does not help

          http://www.seomoz.org/blog/how-to-advanced-relcanonical-http-headers

          Shane

          ACann 1 Reply Last reply Jul 18, 2013, 2:00 PM Reply Quote 1
          • 1 / 1
          1 out of 4
          • First post
            1/4
            Last post

          Got a burning SEO question?

          Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.


          Start my free trial


          Browse Questions

          Explore more categories

          • Moz Tools

            Chat with the community about the Moz tools.

          • SEO Tactics

            Discuss the SEO process with fellow marketers

          • Community

            Discuss industry events, jobs, and news!

          • Digital Marketing

            Chat about tactics outside of SEO

          • Research & Trends

            Dive into research and trends in the search industry.

          • Support

            Connect on product support and feature requests.

          • See all categories

          Related Questions

          • ahmadmdahshan

            Missing Canonical Tag for a PDF document

            canonical

            Error: Missing Canonical Tag
            But URL is not a webpage it is a PDF document, is this fixable?

            Technical SEO | Oct 4, 2023, 7:54 PM | ahmadmdahshan
            0
          • GhillC

            Trailing slash URLs and canonical links

            Hi, I've seen a fair amount of topics speaking about the difference between domain names ending with or without trailing slashes, the impact on crawlers and how it behaves with canonical links.
            However, it sticks to domain names only.
            What about subfolders and pages then? How does it behaves with those? Say I've a site structured like this:
            https://www.domain.com
            https://www.domain.com/page1 And for each of my pages, I've an automatic canonical link ending with a slash.
            Eg. rel="canonical" href="https://www.domain.com/page1/" /> for the above page. SEM Rush flags this as a canonical error. But is it exactly?
            Are all my canonical links wrong because of that slash? And as subsidiary question, both domain.com/page1 and domain.com/page1/ are accessible. Is it this a mistake or it doesn't make any difference (I've read that those are considered different pages)? Thanks!
            G

            Technical SEO | Feb 6, 2019, 8:09 AM | GhillC
            0
          • CREW-MARKETING

            Quick Fix to "Duplicate page without canonical tag"?

            When we pull up Google Search Console, in the Index Coverage section, under the category of Excluded, there is a sub-category called ‘Duplicate page without canonical tag’.  The majority of the 665 pages in that section are from a test environment. If we were to include in the robots.txt file, a wildcard to cover every URL that started with the particular root URL ("www.domain.com/host/"), could we eliminate the majority of these errors? That solution is not one of the 5 or 6 recommended solutions that the Google Search Console Help section text suggests.  It seems like a simple effective solution.  Are we missing something?

            Technical SEO | Nov 13, 2018, 1:07 PM | CREW-MARKETING
            1
          • RevanaDigitalSEO

            Canonical Tag when using Ajax and PhantomJS

            Hello, We have a site that is built using an AJAX application. We include the meta fragment tag  in order to get a rendered page from PhantomJS. The URL that is rendered to google from PhantomJS then is www.oursite.com/?escaped_fragment= In the SERP google of course doesnt include the hashtag in the URL. So my question, with this setup, do i still need a canonical tag and if i do, would the canonical tag be the escaped fragment URL or the regular URL? Much Appreciated!

            Technical SEO | Feb 27, 2015, 11:40 AM | RevanaDigitalSEO
            0
          • NikitaG

            Should I Parent/Child my Website Pages (need help with terminology too)

            Hello I have a website that I am trying to SEO optimise.
            The current structure of the site is that all pages are linked directly after the domain:
            example:   www.domain.com**/page01**  www.domain.com**/page02** The website is however logically organised in the following form:
            www.domain.com**/page01/page02** Sometimes the parenting goes to 3 levels: (please help me with the right term here) Domain
            ↳ Page001
                 ↳ Page002
                      ↳Page003 My question is: should keep the current structure, or is it worth the effort to re-link the website in a parented way. Are there any benefites to one or the other, and could you point to some video tutorials or documentation to read. BqoDAsx.jpg DMMIC5o.jpg

            Technical SEO | Jul 10, 2013, 8:08 PM | NikitaG
            0
          • LukeHutchinson

            Should I include tags in sitemap?

            Hello All, I was wondering if you should include tags and categories in your sitemap. In the past on previous blogs I have always left tags and categories out. The reason for this is a good friend of mine who has been doing SEO for a long time and inhouse always told me that this would result in duplicate content. I thought that it would be a great idea to get some input from the SEOmoz community as this obviously has a big affect on your blog and the number of pages indexed. Any help would be great. Thanks, Luke Hutchinson.

            Technical SEO | Dec 16, 2012, 7:27 PM | LukeHutchinson
            1
          • ShearingsGroup

            Two different canonical tags on one page

            Due to an error, some of my pages now have two canonical tags on them. One is correct and the other goes to a nonsense URL (404 page). I know I should ideally remove the incorrect ones, but it's a big manual job. Are they doing any harm? Can I just leave them there and let Google figure it out? The correct ones are higher up in the code. Will this make a difference? Any help appreciated.

            Technical SEO | Aug 10, 2012, 3:17 PM | ShearingsGroup
            0
          • ChristianMKTG

            Drupal URL Aliases vs 301 Redirects + Do URL Aliases create duplicates?

            Hi all! I have just begun work on a Drupal site which heavily uses the URL Aliases feature. I fear that it is creating duplicate links. For example:: we have http://www.URL.com/index.php and http://www.URL.com/ In addition we are about to switch a lot of links and want to keep the search engine benefit. Am I right in thinking URL aliases change the URL, while leaving the old URL live and without creating search engine friendly redirects such as 301s? Thanks for any help! Christian

            Technical SEO | Nov 11, 2011, 5:29 AM | ChristianMKTG
            0

          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
          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 - 2025 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
          • Accessibility
          • Terms of Use
          • Privacy

          Looks like your connection to Moz was lost, please wait while we try to reconnect.