htaccess http do https

Forcing HTTPS for a specific site

To enable a redirect for a single site, one can specify any of the blocks listed below in .htaccess:

a. RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^ncssltest\.info$ [OR]
RewriteCond %{HTTP_HOST} ^www\.ncssltest\.info$
RewriteRule ^(.*)$ https://www.ncssltest.info/$1 [R,L]

b. RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^ncssltest\.info$|^www\.ncssltest\.info$
RewriteRule ^(.*)$ https://www.ncssltest.info/$1 [R,L]

c. RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?ncssltest\.info
RewriteRule ^(.*)$ https://www.ncssltest.info/$1 [R,L]

Generally, all of the rule sets above do the same job: checking the port (80 for http, 443 for https), verifying whether a domain name in the initial request is with or without “www.” alias, and rewriting the URL with https://. You may choose which one to implement based on your individual preference.”

źródło: https://www.namecheap.com/support/knowledgebase/article.aspx/9770/38/how-to-force-https-using-htaccess-file-in-cpanel

Updated: 12 marca 2017 — 13:53

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Pola, których wypełnienie jest wymagane, są oznaczone symbolem *