1

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]

2
  • Can you clarify how it's not working? And where are these rules defined? Sep 11, 2012 at 4:42
  • Edited to clarify
    – Jo Erlang
    Sep 11, 2012 at 5:22

1 Answer 1

1

First of all it looks like you want to force ssl for all.. I would take care of that first in your *:80 block:

<VirtualHost *:80>

  ServerName abc.com
  ServerAlias www.abc.com        

  Redirect permanent / https://www.abc.com/

</VirtualHost>

Then do your *:443 .. However you can make it real easy and just pull out abc.com into a separate vhost:

NameVirtualHost *:80
NameVirtualHost *:443

<VirtualHost *:80>
  ServerName abc.com
  Redirect permanent / https://www.abc.com/
</VirtualHost>

<VirtualHost *:443>
  ServerName abc.com
  Redirect permanent / https://www.abc.com/
   ....
    ...
   # Note you need a wildcard cert.. I assue you have one already or are using self signed. 
</VirtualHost>

Ok now you redirected all your abc.com to www.abc.com and you can set up this vhost as usual without all the rewrites.

<VirtualHost *:80>

  ServerName www.abc.com        
  Redirect permanent / https://www.abc.com/
</VirtualHost>

<VirtualHost *:443>
  ServerName www.abc.com
  ...
   ....
</VirtualHost>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .