Redirect http to https with htaccess

Redirect http to https with htaccess

Here’s how you can redirect http to https by manually editing your .htaccess¬†file. This will allow you to avoid the need for plugins or the like, while also giving you more control of what you want redirected.

Redirect all HTTP traffic to HTTPS 

# BEGIN HTTPS REDIRECT
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# END HTTPS REDIRECT

Redirect a subfolder or directory only

# BEGIN HTTPS REDIRECT
# edit 'www.example.com' and the subdirectory (the two 'secure')
<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteCond %{SERVER_PORT} !^443$ 
RewriteCond %{REQUEST_URI} secure 
RewriteRule ^(.*)$ https://www.example.com/secure/$1 [R,L]
</IfModule>
# END HTTPS REDIRECT

 

This should work fine on both apache, and litespeed, since both supports the mod_rewrite module

Enjoyed the content ? Share it with your friends !