Connect with HTTPS using htaccess

steven
Posts: 133
Joined: Sun Oct 01, 2017 3:08 pm

Connect with HTTPS using htaccess

Post by steven »

Enter the code below in your .htaccess file to force an HTTPS connection. The code passes parameters if present in the URL. This code was tested with Apache 2.2 and 2.4.

Code: Select all

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
If you use HTTPS change the URL in your website configuration from HTTP to HTTPS. Then check all internal links to pages, images etc. to ensure they are served HTTPS. Use a ../ prefix for internal links instead of the complete URL. Any pages, images or internal links served as HTTP will cause a page is insecure warning for those visiting your website.

In addition to htaccess, if you use Virtual Hosts you can change the settings to use HTTPS by checking the HTTPS settings.

Image