Apache Rewrite HTTP To HTTPS

Apache HTTP Server

Usually this redirection is required when we have enabled ssl in Apache and want all users to be redirected to secure url once they type in the application address. We have achieve the same in below two ways.

Method 1:

– Open httpd.conf file and enable mode_rewrite module like below

LoadModule rewrite_module modules/mod_rewrite.so


– Add below configurations to httpd.conf file

RewriteEngine On
RewriteCond %{HTTPS}% off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI }

– Restart the Apache services.

Method 2:

– Open httpd.conf file and enable mode_rewrite module like below

LoadModule rewrite_module modules/mod_rewrite.so

– Configure the below properties, make sure both 80(NONSSL) and 443(SSL) ports are present

Listen 80
Listen 443

ServerName MyServerFQDN:80
ServerName MyServerFQDN:443

– Search for VirtualHost and place the below properties just above the current virtualhost.

ServerName MyServerFQDN
Redirect permanent / MyServerFQDN:443

– Restart the Apache.

In case of any ©Copyright or missing credits issue please check CopyRights page for faster resolutions.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.