Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Remco Tolsma

    (@remcotolsma)

    This is currently not possible, but maybe you can create 2 domain pages. One for with www and one without www, with the SEO plugin from Yoast can redirect one to the other. And you could always redirect everything one to the other with a few .htaccess rules.

    www to non-www

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

    Source: https://stackoverflow.com/a/1270281

    non-www to www

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://www.%1/$1 [R=301,L]

    this htaccess can perhaps be improved upon somewhat (eg. less ‘footprint’ from wildcard matches and value captures) in this use case as follows:

    www to non-www

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

    non-www to www

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
    RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]

    and ONLY if using 100% HTTPS

    www to non-www

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,S=1]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    non-www to www

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
    RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,S=1]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using both with or without the 'www'’ is closed to new replies.