mod_rewrite not working fully?

January 15, 2015 782 views

So I am using the following

<VirtualHost *:80>
RewriteEngine on
ReWriteCond %{SERVERPORT} !^443$
RewriteRule ^/(.*) https://%{HTTP
HOST}/$1 [NC,R,L]
</VirtualHost>
<VirtualHost *:443>
etc.....

and it does not redirect all traffic to the appropriate named version, it goes to SSL but not the domain setup.
I am using only domain.com and not www.domain.com so my SSL cert is registered to mydomain.com and not the www version, and it does redirect to the SSL version but not to just the https://domain.com version. open to suggestions please?

1 Answer

Just to add, I have tried the following and it seems to work on IE. but not Chrome.
<VirtualHost *:80>
RewriteEngine on
RewriteCond %{HTTPHOST} !^domain.com$ [NC]
ReWriteCond %{SERVERPORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
</VirtualHost>

Have another answer? Share your knowledge.