Redirect non-www to www over http and https

Use the following .htaccess code to redirect non-www URLs to www over http and https.
Create, or edit if already exists, .htaccess file in the root directory (web / httpdocs / www) of web hosting account and add in the code below:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Was this answer helpful?

Also Read

Point your home page URL to a subdirectory

Method 1 - Redirect your main domain to a subfolder on that domain: RewriteEngine On# Change...

Secure Joomla with .htaccess

Advanced .htaccess rules that will overall secure and increase the speed of your Joomla...

Leverage Browser Caching using .htaccess

Add the following .htaccess rules to the very end of your .htaccess file to reduce the load times...

Block visitors by IP address using .htaccess

Deny access based upon IP address, or an IP block, by placing the following code into your...

Speed up WordPress Leveraging Browser Caching via .htaccess

Insert the following code to your .htaccess file to increase the speed of your WordPress website...