Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 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

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.


share|improve this question
Have you thought of possibly using Rewrite rules? –  mdpc Aug 6 '12 at 20:42

3 Answers 3

up vote 0 down vote accepted

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]
share|improve this answer
NameVirtualHost directive is deprecated in Apache 2.4.x, its no longer necessary. –  Vivek Thomas Oct 16 '14 at 10:42

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.

share|improve this answer
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 '12 at 17:27

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 *:443>
share|improve this answer
That could work, will virtualhost rewrite rules interfere with the rewrite rules the application already has in .htaccess, etc? –  user129545 Aug 6 '12 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. –  funny_ha_ha Aug 7 '12 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 '12 at 11:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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