I need help with a PHP canonical URL tags
-
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.
-
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
-
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.
-
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
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
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.
Related Questions
-
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.
Technical SEO | | GhillC
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!
G0 -
Wrapping my head around an e-commerce anchor filter issue, need help
I am having a hard time understanding how Google will deal with this scenario, I would love to hear what you guys think or suggest. Ok a category page on the site in question looks like this. http://makeupaddict.me/6-skin-care All fine and well, But a paginated page or a filtered category pages look like these http://makeupaddict.me/6-skin-care#/page-2 and http://makeupaddict.me/6-skin-care#/price-391-1217 From my understanding Google does not index an anchor without a shebang (#!), but that doesn't mean that they do not still crawl them, correct? That is where the issue comes in, since anchors are not indexed and dropped from the urls, when Google crawls a filtered or paginated page, it is getting different results. From the best of my understanding, and someone can correct me if I am wrong but an anchor is not passed in web languages like a querystring is. So if I am using php and land on http://makeupaddict.me/6-skin-care or http://makeupaddict.me/6-skin-care#/price-391-1217 and use something like .$_SERVER['SELF'] to get the url both pages will return http://makeupaddict.me/6-skin-care since the anchor is handled client side. With that being the case, is it imagined that Google uses that standard or is it thought they have a custom function that grabs the whole url anchor in all? Also if they are crawling the page with the anchor, but seeing it anchor less how are they handling the changing content?
Technical SEO | | LesleyPaone0 -
Should I use a canonical tag or 301 with Wordpress posts?
Hi all, I'm trying to determine if canonical or 301 is a better way of handling an issue on my site. The Background I've got a Wordpress website where pages are in-depth reference articles and the posts are for short news blurbs. When I produce a new resource page, I also make a short post telling readers about the new resource. I use Yoast's Wordpress SEO plug in. Sometimes, Google will rank the 200 word post higher than the 2000 word resource page. I suspect that is because of the order in which they were crawled by Google, but I do not know for sure. The Question To make sure that the resource page is seen as the most important location on the site for the topic, should I use the canonical section in the Yoast plugin on the post to point to the page? Or should I wait, and after a few days (when the news blurb is off of the first page) just 301 the post to the page? Are there any link juice considerations when using the canonical option? Thanks for the help! Richard
Technical SEO | | RichardInFlorida0 -
Need Help With WWW vs. Non-WWW Duplicate Pages
A friend I'm working with at RedChairMarket.com is having duplicate page issues. Among them, both www and non-www URLs are being generated automatically by his software framework, ASP.net mvc 3. How should we go about finding and tackling these duplicates? Thanks!
Technical SEO | | BrittanyHighland0 -
How do I properly use the canonical tag to avoid negative effect from having identical content on 2 url’s?
To illustrate… I have same website uploaded at 2 locations (url’s). Only the domain extensions are different. www.myexample.com
Technical SEO | | swiftseo
www.myexample.org The benefit is that I may run some promos on one location and not the other to help in product surveys/testing. The website content is 98% identical and I understand this content duplication may cause SEO problems. The domain I wish to use for rankings etc is www.myexample.com 1) How do I go about avoiding seo problem? Do I need to place the canonical tag at www.myexample.org ie 2) Do I also place the exact same tag at the .com location or not necessary there? Is there an alternative or more effective option to resolving the problem?0 -
I need help to define which is the best friendly url structure
Hi, I need some help to define which is the best friendly url structure for my new project, I'm in doubt for some cases, anyone could help me define which would be the best way? domain.com/buy-online/0-1,this-cool-model or
Technical SEO | | LeonardoLima
domain.com/buy-online/this-cool-model,0-1 or
domain.com/buy-online/0-1/this-cool-model or
domain.com/buy-online/this-cool-model/0-1 or
domain.com/buy-online/this-cool-model_0-1 or
domain.com/buy-online/this-cool-model?Model=0&OtherParam=1 Thanks! Best Regards,
Leonardo Lima0 -
Multiple URLs
I'm trying to check the URLs of this site- http://www.ofo.com.au, and I see that their old site has 301 re-directed to it...but the site http://ofo.com.au and http://outdoorfurnitureoutlet.com.au are both still up and I can't see any 301 redirects from them. Is it a problem even if when I do a site: search for them I get no results?
Technical SEO | | UnaRealidad0 -
Robots.txt and canonical tag
In the SEOmoz post - http://www.seomoz.org/blog/robot-access-indexation-restriction-techniques-avoiding-conflicts, it's being said - If you have a robots.txt disallow in place for a page, the canonical tag will never be seen. Does it so happen that if a page is disallowed by robots.txt, spiders DO NOT read the html code ?
Technical SEO | | seoug_20050