2

I have a couple http (port 80) vhosts that I want to redirect to http if an https request is made to them. Apparently some things have changed with Apache 2.4 (NameVirtualHost not used like it was in the past, etc).

Apache 2.4 on centos 5.5, This is all using a single ip for all vhosts below, I don't have multiple ip's on this box,

my /usr/local/apache2/conf/extra/httpd-vhosts.conf :

#
<VirtualHost www.dom1.com:80>
    ServerName www.dom1.com
    ServerAlias dom1.com
    DocumentRoot /usr/local/apache2/htdocs/dom1/wordpress
</VirtualHost>


<VirtualHost webmail.dom2.com:443>
    ServerName webmail.dom2.com
    DocumentRoot /usr/local/apache2/htdocs/webmail

    SSLEngine On
    SSLCertificateFile /usr/local/apache2/webmail.crt
    SSLCertificateKeyFile /usr/local/apache2/webmail.key
</VirtualHost>
#

my /usr/local/apache2/conf/extra/httpd-ssl.conf,

#
Listen 443

SSLPassPhraseDialog  builtin
SSLSessionCache         shmcb:/var/cache/mod_ssl/scache(512000)
SSLSessionCacheTimeout  300
Mutex default
SSLRandomSeed startup file:/dev/urandom  512
SSLRandomSeed connect builtin
SSLCryptoDevice builtin
#

webmail.dom2.com works fine. Problem is I can connect to https://www.dom1.com, and it serves up the content from webmail.dom2.com. I want any https requests for www.dom1.com on port 443 to simply redirect to http://www.dom1.com on port 80.

Thanks

1
  • Have you thought of possibly using Rewrite rules?
    – mdpc
    Aug 6, 2012 at 20:42

3 Answers 3

2

Above Listen 443 add (if it is not defined elsewhere)

NameVirtualHost *:443

Then before the virtualhost for webmail.dom2.com:443 add this virtualhost with redirect

<VirtualHost *:443>
    ServerName www.dom1.com
    ServerAlias dom1.com
    RewriteEngine On
    RewriteCond %{SERVER_PORT} 443
    RewriteRule ^/(.*)$ http://www.dom1.com/$1 [R]
</VirtualHost>
1
  • NameVirtualHost directive is deprecated in Apache 2.4.x, its no longer necessary. Oct 16, 2014 at 10:42
0

i think changing the httpd-ssl.conf "listen 443" line to "listen webmail.ip:443 could help. That way dot1.com traffic will never come webmail.

1
  • I should add, this is all on a single ip address. I don't have multiple ip's in this case for 80 vs 443, etc.
    – user129545
    Aug 6, 2012 at 17:27
0

i'm doing this the other way around on one of my server using rewrite rules. should be trivial to just change it:

<VirtualHost *:80>
    RewriteEngine On
    # Rewrite HTTPS
    RewriteCond %{HTTPS} !=on
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{HTTP_HOST} ^(.*)$
    RewriteRule ^/(.*)$ https://%1/$1 [R]
</VirtualHost>

<VirtualHost *:443>
    [...]
</VirtualHost>
3
  • That could work, will virtualhost rewrite rules interfere with the rewrite rules the application already has in .htaccess, etc?
    – user129545
    Aug 6, 2012 at 23:26
  • as this rule would be defined in the https vhost, it should not interfere with rules you deploy in the http vhost.
    – Marco
    Aug 7, 2012 at 11:08
  • Yep, I meant the other rules within the app served by the vhost. But I'll test it out. Thanks.
    – user129545
    Aug 7, 2012 at 11:58

You must log in to answer this question.

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