ebol4
ebol4

Reputation: 152

Htaccess redirects http://www... to https://www..., but does not redirect http://www

I'm trying to make it so that no matter how my website is accessed:

All of these redirect to the same place:

The latter two, http://www... and https://mywebsite..., both work, but not the first one. The first one gets redirected to http://www.// for some reason. Here's my sites-enabled/000-default that does the redirecting:

<VirtualHost *:80>
    ServerName www.metalmetalland.com
    ServerAlias *.metalmetalland.* metalmetalland.* metalmetalland.com

    RewriteEngine On             
    #redirect all port 80 traffic to 443
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^/?(.*) https://www.metalmetalland.com/$1 [L,R]

    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel debug
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Upvotes: 0

Views: 1071

Answers (1)

user4035
user4035

Reputation: 23729

Try this:

RewriteEngine On
#not https
RewriteCond %{HTTPS} off
RewriteRule .* https://www.metalmetalland.com%{REQUEST_URI} [R=301,L]

#https, but not www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Upvotes: 1

Related Questions