Apache rewrite redirect to https and www
- by Jo Erlang
I need to get mod_rewrite to do the following
http://abc.com -> https://www.abc.com
https://abc.com/login -> https://www.abc.com/login
http://www.abc.com?x=3 -> https://www.abc.com?x=3
https://abc.com/login?x=1 -> https://www.abc.com/login?x=1
http://www.abc.com/login?x=3 -> https://www.abc.com/login
I have the following, in my abc.com.conf vhost file but its not work correctly
<VirtualHost *:80>
ServerName abc.com
ServerAlias www.abc.com
RewriteCond %{HTTP_HOST} ^abc\.com
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=permanent,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.abc.com/%{REQUEST_URI}
</VirtualHost>
<VirtualHost *:443>
ServerName abc.com
ServerAlias www.abc.com
RewriteCond %{HTTP_HOST} ^abc\.com
RewriteRule ^(.*)$ https://www.abc.com/$1 [R=permanent,L]
</VirtualHost>
Can anyone help me out on the rest?
[edited to clarify]