admin/ July 9, 2016/ Linux/ 0 comments

Force rewrite url to https using .htaccess

by admin

Force rewrite url to https using .htaccess

To force rewrite url on https using the .htaccess file.

Open the .htaccess file and add the below code after the rewrite engine on.

nano /var/www/html/.htaccess

Paste the below code

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Note-: Please verify the rewrite module is enabled.

$ sudo apache2ctl -M | grep rewrite

if not enabled then please use the below command-:

$ sudo a2enmod rewrite
$ sudo service apache2 restart

Leave a Reply