Jun
7
Published by Kieran in Computer Science
ยท Leave your thoughts
( words)
( words)
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