Let's say you have the domain ethernetservers.com and wish to have it automatically redirect to https://www.ethernetservers.com (note the https:// and www.) when visitors go to ethernetservers.com, this can be easily achieved using htaccess!

Create (or modify) a file called ".htaccess" in your domain's root directory, and add the following:

RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

That's it, you're done! 

Please note, you may need to clear your browser cache (or try another web browser) to see the change take effect. 

Was this answer helpful? 0 Users Found This Useful (1 Votes)