Reputation: 14426
I have an .htaccess file that redirects a user to the www subdomain if there is no subdomain, however I want to also take into consideration if they are accessing via http or https.
How can I redirect to the correct protocol?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
Upvotes: 1
Views: 127
Reputation: 785541
You can use this modified rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Upvotes: 1