Tuesday, April 5, 2016

In this post I'll explain how we can redirect all HTTP traffic to HTTPS. Here I'm using Apache2 and its rewrite module to achieve this.

You can refer the following configuration from apache.

RewriteEngine on

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

In the above configurations I'm rewriting all HTTP traffic to its HTTPS URL.

http://yenlo.com/t  ==> https://yenlo.com/t

Full Apache configs will look like following.

<VirtualHost mod_rewrite.c *:80>
        ServerName yenlo.com
        ServerAlias yenlo.com

RewriteEngine on

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

</VirtualHost>

<Virtualhost *:443>
ServerName yenlo.com
ServerAlias yenlo.com
ProxyPreserveHost On
# ProxyRequests On
SSLEngine On
SSLProxyEngine On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

ProxyPass /t https://10.100.5.112:9443/t
ProxyPassReverse /t https://10.100.5.112:9443/t

</Virtualhost>


Thanks for reading and please drop a comment if you have any queries.
Categories:

0 comments:

Post a Comment

Subscribe to RSS Feed Follow me on Twitter!