• Hello,

    I understand that for SEO reasons it is better to force browsers/web crawlers to use either the www or “non”www version of your domain. Apparently it doesn’t seem to matter which but you need to choose one and enforce it.

    Currently I have this in my .htaccess file to force the SSL version of my domain URL.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
    </IfModule>

    It works well enough for that purpose.
    However it doesn’t force the www version of my URL which is what i want.

    If I simply do this:

    RewriteRule ^(.*)$ https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

    I guess that would work for urls that point to https://mydomain.com
    but it wouldn’t catch https://mydomain.com

    Any help appreciated.

    • This topic was modified 7 years, 9 months ago by TWD.
    • This topic was modified 7 years, 9 months ago by TWD.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The first code you have should do it. I use that same https rewrite code on a dozen sites and it automatically removes the www. I would leave out the www. It makes your url longer and harder to remember.

    You can try something like this. Modify to add or remove “www.” as desired.

    # If HTTPS is off then 301 to HTTPS
    RewriteCond %{HTTPS} off
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    # If HTTP_HOST does not start with www. then 301 to www.
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to set cannonical https://www in .htaccess’ is closed to new replies.