What's the best syntax to use in rel="canonical" in this context?
You guys taught me that it's good practice to use "canonical" to establish a single universal url to a page that can be accessed via multiple urls.
For context, I have this .htaccess code reformatting my urls :
RewriteEngine On
##### FORCE SECURE URL
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
##### REMOVE /PAGES FROM URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/pages/
RewriteRule ^(.*)$ /pages/$1##### REMOVE .PHP FROM URL
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
What it does is :
- Redirects all regular connections to secure ones (http:// to https://)
- Makes it possible to access pages with or without the location of their folder in the url (/pages)
- Makes it possible to access pages with or without the file extension in the url (.php)
(Additionally, since I don't usually include "www" in my advertising, I favor the non-www version of the url over the one with it.)
As a result from all that, every page can be accessed at least half a dozen different ways.
Ideally, I'd like "domain.com/page" to be the recognized format.
The shorter the better, IMO.
But I'm still not sure which of these 3 syntaxes would be best to include in the rel="canonical" link (or if the 3rd one would even work) :
- <link rel="canonical" href="http://domain.com/page" />
- <link rel="canonical" href="https://domain.com/page" />
- <link rel="canonical" href="//domain.com/page" />
In a perfect world, all links would lead to "domain.com/page" (in secure mode). I'm just not 100% sure of the syntax to get there. In fact, if I knew how to rewrite that .htaccess code to redirect to the correct syntax of the url (instead of allowing all versions of the url to work, as it currently does) I just might.
Thanks in advance!
