1

I am running Apache 2.4.18 on Windows Server 2008 R2 and PHP 5.6.18.

My Apache server by default have SSL turned on. I need to run 2 different sites where one site uses SSL and the other one does not.

Here is what I have added to my httpd-vhosts.conf file in attempt to get it to work

<VirtualHost *:80>
   ServerName SERVER1.example.com
   Redirect permanent "C:/phpsites/app1" https://sub1.example.com/
</VirtualHost>


<VirtualHost *:80>

    DocumentRoot "C:/phpsites/app2/public"
    ServerName SERVER1.example.com
    ServerAlias sub2.example.com

    SSLEngine Off

    <Directory "C:/phpsites/app2/public">
        AllowOverride All
        Require all Granted
    </Directory>

</VirtualHost>


<VirtualHost *:443>

    DocumentRoot "C:/phpsites/app1"
    ServerName SERVER1.example.com
    ServerAlias sub1.example.com

    SSLEngine On
    SSLCertificateFile "c:/Apache24/conf/certificate/cert.crt"
    SSLCertificateKeyFile "c:/Apache24/conf/certificate/private.key"

    <Directory "C:/phpsites/app1">
        AllowOverride All
        Require all Granted
    </Directory>

</VirtualHost>

The setting above does not work properly. When I go to **https**://sub1.example.com Apache redirects me to the correct site C:/phpsites/app1. When I go to **http**://sub1.example.com it redirects me to C:/phpsites/app2/public but I don't want that to happen. And when I go to http://sub2.example.com I get redirected to **https**://sub1.example.com for some reason.

I need to direct any user that is looking for http://sub1.example.com or https://sub1.example.com to **https**://sub1.example.com.

And any users that is looking for http://sub2.example.com or https://sub2.example.com to go to **http**://sub2.example.com

How can I get this to work?

UPDATED

Here is what I get when I execute httpd -D DUMP_VHOSTS

VirtualHost configuration:

*:80 is a NameVirtualHost


default server SERVER1.example.com (C:/Apache24/conf/extra/httpd-vhosts.conf:27)
port 80 namevhost SERVER1.example.com (C:/Apache24/conf/extra/httpd-vhosts.conf:27)

port 80 namevhost SERVER1.example.com (C:/Apache24/conf/extra/httpd-vhosts.conf:34)
 alias sub2.example.com


*:443 is a NameVirtualHost
default server SERVER1.example.com (C:/Apache24/conf/extra/httpd-vhosts.conf:52)
port 443 namevhost SERVER1.example.com (C:/Apache24/conf/extra/httpd-vhosts.conf:52)
 alias sub1.example.com

port 443 namevhost SERVER1.example.com (C:/Apache24/conf/extra/httpd-ssl.conf:85)
0

When I go to http://sub1.example.com it redirects me to C:/phpsites/app2/public but I don't want that to happen.

It's because you have only one (default) http virtual host

<VirtualHost *:80>

    DocumentRoot "C:/phpsites/app2/public"
    ServerAdmin test@example.com
    ServerName sub2.example.com
    ServerAlias sub2.example.com

    SSLEngine Off

    <Directory "C:/phpsites/app2/public">
        AllowOverride All
        Require all Granted
    </Directory>

</VirtualHost>

You must add virtualhost for sub1.example.com

<VirtualHost *:80>
   ServerName sub1.example.com
   Redirect 301 / https://sub1.example.com/
</VirtualHost>

The following line is really strange

port 80 namevhost sub1.example.com (C:/Apache24/conf/extra/httpd-vhosts.conf:43) alias sub2.example.com

Why are you using sub2 as alias in sub1 vhost?

  • You must have both http virtualhosts for sub1 and sub2. From the question I can see only one – ALex_hha Feb 23 '16 at 23:28
  • Thank you for your comment. I added the code you posted to the httpd-vhosts.conf file and restarted apache. But still when I got to sub2.example.com or sub2.example.com I get directed to sub1.example.com instead on sub2.example.com – Junior Feb 23 '16 at 23:34
  • Add output of the 'apache2ctl -t -D DUMP_VHOSTS' to the question – ALex_hha Feb 23 '16 at 23:40
  • I executed the command httpd -D DUMP_VHOSTS I think it is the same as what you asked me to do except for windows and I updated the results in my question. – Junior Feb 23 '16 at 23:53
  • I updated my question again with the current DUMP_VHOSTS output and the current httpd-vhosts.conf content Maybe this one makes more since – Junior Feb 24 '16 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.