htaccess rule to add https

1

I'm trying to create a rule inside my htaccess so it's added to the HTTPS url. It turns out that this should happen only for a specific domain, how to handle this in a rewritecond http_host?

example:

RewriteCond %{HTTP_HOST} palavraChave
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Would it be possible?

    
asked by anonymous 17.10.2017 / 19:19

2 answers

0

You can do this.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^suaurl\.com.br [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}
    
17.10.2017 / 19:23
0

I know two methods:

Important : Do not force HTTPS if your site does not have SSL certificate.

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

Or

    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80 /*porta que utiliza*/
    RewriteRule ^(.*)$ https://site.com.br/$1 [R,L]
    /*Linha 2: Condiciona que todo acesso vindo da porta 80 será afetado pela regra;*/
    /*Linha 3: Definição da regra, neste caso, sempre utilizar o https:// mesmo quando acessado por http.*/

UPDATE1

For only 1 domain:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^seudominio\.com [NC] /* aqui é como um if */
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}

or if you prefer something clearer, but it does the same thing:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?seudominio.com$
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [NC,L,R]

If it is useful, do not forget to evaluate, this helps a lot, abs

    
18.10.2017 / 21:07