<link rel="canonical" href="<? php echo DEFAULT_CANONICAL; ?>" >
There is an error in the opening PHP tag that will result in this error, and without any feedback to comments we can only assume this is as written in your actual code - not simply a typo in your question?
The erroneous space in <? php
(it should be <?php
) will fail to get the enclosed PHP interpreted as PHP code and will be sent to the browser as written - as malformed HTML! If this is the case then "The Specified Canonical Link" will indeed "Point to a Different page" - it won't point to any valid page!
You need to remove the erroneous space in the opening PHP tag, or use short-echo tags instead (for this kind of templating):
<link rel="canonical" href="<?=DEFAULT_CANONICAL?>" >
The value of DEFAULT_CANONICAL is https://domain_of_my_website/.$_SERVER['REQUEST_URI'])
However, as noted in comments, you can't reliably construct the canonical URL by simply using PHP's $_SERVER['REQUEST_URI']
variable without additional parsing. This variable contains query string parameters that can be manipulated by the user - changing the canonical URL in the HTML and potentially making your site vulnerable to XSS attacks.
<? php echo
- Do you really have a space between<?
andphp
? That is not valid and will be sent as plain text to the browser (although that would be obvious by looking at the HTML source). (?) – MrWhite Mar 6 '20 at 18:16<? php
in your actual code, or is it a typo in your question? (That would certainly cause the problem you are getting.) However, you can't reliably use$_SERVER['REQUEST_URI']
to refer to the canonical URL. Unless you've manually overridden this? Since PHP'sREQUEST_URI
variable contains the query string, which could be manipulated by a user. In other words, it's vulnerable to XSS. – MrWhite Mar 6 '20 at 19:51