1. Home
  2. Docs
  3. Cloudways
  4. Canonical Urls
  5. Canonical Url Redirecting

Canonical Url Redirecting

For the main site, the canonical url should be https://www.wpinstall.net . This avoids some cookie sharing issues. For the subdomain sites the canonical url is ‘dev.wpinstall.net’ . All sites appear as subdomains.

Setting up the canonical redirects using chrome is a major pain, because it tries to be smart about deciding what url you really want. You enter ‘site.tld’ and Chrome expands it to maybe ‘https://www.site.tld. The trick is to force Chromes hand by entering a full url including the leading http(s)://. Use Ctrl-Shift-I to bring up the network pane and enter full urls to test.

The final htaccess rules are simple.

##  Canonical https
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]

##  CANONICAL non-WWW
RewriteCond %{HTTP_HOST} ^www\.neon\.wpinstall/.net [NC]
RewriteRule ^(.*)$ https://neon.wpinstall.net/$1 [L,R=302]

##  canonical WWW
#RewriteCond %{HTTP_HOST} !^www.helium.wpinstall.net$ [NC]
#RewriteRule ^(.*)$ https://www.helium.wpinstall.net/$1 [L,R=302]