Domain redirection in .htaccess file

1

I have a domain like this: https://www.dominio.com , which always has to access this way.

So I need to do some redirects. These are:

From:

(http) www.dominio.com.br
(http) www.dominio.com
https://www.dominio.com.br

To:

https://www.dominio.com

What I've done so far:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^(www\.)?dominio\.com$ [NC]
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} ^(www\.)?dominio\.com\.br$ [NC]
    RewriteRule ^(.*)$ https://dominio\.com/%{REQUEST_URI} [L,R=301]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

The only problem is this:

But it does not redirect when I type https://www.dominio.com.br .

    
asked by anonymous 06.06.2017 / 14:06

1 answer

2

Let's break it down:

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^www\.(.*)$ # REMOVE O www DA FRENTE DO DOMINIO
    RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,L]

    RewriteCond %{HTTP_HOST} (.*)\.br$ # REMOVE O br DO FINAL DO DOMINIO
    RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,L]

    RewriteCond %{HTTPS} off # CASO NAO ESTEJA EM https ALTERA PARA POR https
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-d # SE O CAMINHO NÃO FOR UM DIETORIO
    RewriteCond %{REQUEST_FILENAME} !-f # SE O CAMINHO NÃO APONTA PARA UM ARQUIVO
    RewriteRule ^(.*)$ index.php [L] # QUALQUER REQUISIÇÃO VAI PARA index.php

</IfModule>
    
06.06.2017 / 15:25