Reputation: 33
I need to force www. on a subdomain, e.g. sub.website.com to www.sub.website.com
I have tried a lot of codes e.g.
RewriteCond %{HTTP_HOST} !^www\.dev.website\.com
RewriteRule (.*) http://www.dev.website.com/$1 [R=301,L], no success
Tried:
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] no luck.
If you have an answer please reply. Thanks Thanks.
Upvotes: 1
Views: 886
Reputation: 785481
You can try this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.website.\com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Upvotes: 1