1

I'm trying to add the rel=canonical tag to only one page. In order to add the tag, I need to add it to the part, in the mod_header.php file. This will add the same rel canonical tag to all the pages of my website.

How can I add rel canonical to only one page. I don't want to do a 301 redirect, I want to add a rel=canonical tag.

Can this be done with some .htaccess code?

4

Add to htaccess:

<Files "file.html">
Header add Link "<http://www.example.com>;rel=\"canonical\""
</Files>

For further info read: https://moz.com/blog/how-to-advanced-relcanonical-http-headers

12
  • i just did that and it seems ok but how do i check if it´s really working? Sep 30 '15 at 12:59
  • 1
    Open FireBug or another developertool and check the tab NET (that's the name in FireBug)
    – Martijn
    Sep 30 '15 at 13:49
  • look at the loaded page with developer tools, the go to network->file and look into response header info
    – Evgeniy
    Sep 30 '15 at 13:50
  • not working. maybe because it´s a dynamic page. is that possible? in that case how i do procced? Oct 1 '15 at 9:47
  • what part isn't working? canonical setting or checking whether the setting would work?
    – Evgeniy
    Oct 1 '15 at 9:54
2

To answer the original question, in PHP:

header('Link: <http://example.com/path/to/page.html>; rel="canonical"');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.