Sunday, November 16, 2014

Redirect http to https with multiple VirtualHost on apache

Goal: Redirect all http to https, domain are config.example.com and configure.example.com.

When first try on it, I encountered redirect problem, when you dont place carefully the virtual host, redirection will got problem, so on my example, I need to place carefully, config http then https, and configure http then https. It should also redirect properly when you have a sub folder.

Note: I changed the tags to |



|VirtualHost *:80|
ServerName config.example.com/
RedirectMatch 301 /(.*)$ https://config.example.com/$1




|/VirtualHost|


|VirtualHost *:443|
        SSLEngine on
        SSLProtocol -ALL -SSLv3 +TLSv1
        SSLCipherSuite ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM
        SSLCertificateFile /etc/pki/example_cert_2017/example.com.crt
        SSLCertificateKeyFile /etc/pki/example_cert_2017/example.key
        SSLCertificateChainFile /etc/pki/example_cert_2017/gd_bundle.crt
        ServerName config.example.com
        ServerAlias config.example.com
        DocumentRoot "/data/www/config"
        ErrorLog logs/ssl-config-error_log
        CustomLog logs/ssl-config-access.log common

|/VirtualHost|


|VirtualHost *:80|
ServerName configure.example.com
RedirectMatch 301 /(.*)$ https://configure.example.com/$1

|/VirtualHost|


|VirtualHost *:443|
        SSLEngine on
        SSLProtocol -ALL -SSLv3 +TLSv1
        SSLCipherSuite ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM
        SSLCertificateFile /etc/pki/example_cert_2017/example.com.crt
        SSLCertificateKeyFile /etc/pki/example_cert_2017/example.key
        SSLCertificateChainFile /etc/pki/example_cert_2017/gd_bundle.crt
        ServerName configure.example.com
        ServerAlias configure.example.com
        DocumentRoot "/data/www/configure"
        ErrorLog logs/ssl-configure-error_log
        CustomLog logs/ssl-configure-access.log common

 |/VirtualHost|