Redirect non-www to www. using .htaccess

Find an article
Jun 7
Published by in ยท Leave your thoughts
( words)
Warning! There was an error loading some of the images for this post.

The below .htaccess code will redirect all non-www traffic to www while maintaining the protocol used by the client. The best part is you don’t have to worry about hardcoding the domain or URI!

# Redirect non www to www.
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Credit: unknown

Leave a Reply

Your email address will not be published.