Apache Always Redirect to HTTPS for SSL Websites

After getting an SSL certificate, it is usually good idea to redirect all http (port 80) connections on your website to https (port 443). This can be simply done in Apache. To do this, just go to your public_html folder and either create a .htaccess file and add these lines, or add them to the already existing .htaccess file:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Note: The Apache mod_rewrite must be enabled for this to work!

Leave a Reply

Your email address will not be published.