We will make a flowchart of the PHP script that will be able to place the canonical tag at the source of any non-canonical URL issues without the use of .htaccess or redirections. Basically there are four domain canonical scenarios:
Each of these URL canonical scenarios requires different PHP scripts, but the flow of implementation is the same. Here is an example that illustrates a site using http:// and www: as their canonical version. Step 1: If the domain is using session IDs, this should be stripped off first as it is not needed as part of the canonical version. Step 2: Check to see if the requested protocol is http://. If it is not, return the http version to the browser and append results with Step 3. Step 3: If the requested URL dos not use www, append www to the URL; otherwise, return it to the browser. The final canonical URL should:
In the rest of this article, I'll show you the recommended PHP canonical scripts for the four scenarios discussed above.
blog comments powered by Disqus |