How to redirect http to https (SSL) using .htaccess and mod_rewrite with Apache web server

No GoodNeed ImprovementOKGoodExcellent (1 votes, average: 5 out of 5)
Loading ... Loading ...

If you want to use https (SSL) for the entire web site, edit .htaccess and add the following lines:


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

if you want to enforece https (SSL) for a paticular directory (and sub-directories), create an .htaccess file with the following lines:



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

Make sure you turn on RewriteEngine in your httpd.conf file:

RewriteEngine on

Then restart apache

apachectl restart

Popularity: 1%

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word