PHP script for general all pages canonical script

The following script will work well as a general in-header canonical one-line script, BUT ONLY FOR SITES THAT DON’T PASS PARAMETERS TO GENERATE CONTENT PAGES. This means that the parameters do not affect the content generated.
The script will mark as canonical the URL without the parameters part – the part that follows the “?” sign.
If your site uses URL like “site.com?page=38” then this code will not do its job – it will confuse Google into thinking your site is based on one main page – “site.com”
If you have URL that you reach with different parameters, BUT THE PAGE IS STILL THE SAME PAGE then this is perfect:

Leave a Reply

Your email address will not be published. Required fields are marked *