hoangweb
3/15/2018 - 1:56 PM

htaccess - https ssl

Options +FollowSymlinks
RewriteEngine On
#-------- way 1
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://example.com/$1 [R]

# Forcing HTTPS for a specific site
RewriteCond %{HTTP_HOST} ^ncssltest\.info$ [OR]
RewriteCond %{HTTP_HOST} ^www\.ncssltest\.info$
# or RewriteCond %{HTTP_HOST} ^ncssltest\.info$|^www\.ncssltest\.info$
RewriteRule ^(.*)$ https://www.ncssltest.info/$1 [R,L]

#-------- way 2
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#-------- way 3
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

# Enabling HTTPS for a specific subfolder
RewriteRule ^/?subfolder/(.*) https://%www.ncssltest.info/subfolder/$1 [R,L]

# Forcing HTTPS for a specific page
RewriteRule ^example\.html$ https://www.ncssltest.com/example.html [R,L]