I'd like to have:
http://example.com
redirect to:http://www.example.com
https://example.com
redirect to:https://www.example.com
And anything that is http://whatever.example.com
NOT append the www like http://www.whatever.example.com
.
I'd like to have:
http://example.com
redirect to: http://www.example.com
https://example.com
redirect to: https://www.example.com
And anything that is http://whatever.example.com
NOT append the www like http://www.whatever.example.com
.
Try adding this
RewriteCond
to your .htaccess file to catch SSL only - then do the same thing for standard http.Try this rule:
Here’s an explanation:
on
andoff
) ands
(so eitherons
oroffs
) is equal toons
and captures thes
. This means if%{HTTPS}s
evaluates toons
, the first matching group iss
and empty otherwise.^
) and redirects them to the evaluated value ofhttp%1://www.%{HTTP_HOST}%{REQUEST_URI}
if both conditions are true. Where%1
is the first matching group of the previous condition (s
if HTTPS and empty otherwise),%{HTTP_HOST}
is the HTTP Host of the request and%{REQUEST_URI}
is the absolute URL path that was requested.