Domain forwarding in file . htaccess

Asked

Viewed 268 times

1

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

So I need to do some redirects. These are the ones:

Of:

(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 doesn’t redirect when I type https://www.dominio.com.br.

  • It wouldn’t just be fixating on dominance.? RewriteRule ^(.*)$ https://www.dominio.com/$1 [L,R=301]

  • It didn’t work. The problem is when I type https://www.dominio.com.br., it does not redirect and gives that security error page. Why it has no certificate in that domain.

  • both domains are yours? if you do not own the .com he will not point to your service.

  • They’re both mine, the .com and the .com.br. They are redirected to the IP of my server.

1 answer

2


Let’s go in pieces :

<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>
  • Guilherme, I was not the one who said no. Look, I edited my question and put my whole . htaccess. It’s from Laravel. I did what you said, but it was a mistake on the site.

  • @Diegosouza see the issue, it may be for the second reason, tlz reversing the order resolve

  • Your answer solved, but it was not because of the order. The certificate is installed on .com. What I did was remove the other conditions that Laravel places, just like you did. Thank you!

  • @Diegosouza glad you solved :D

  • William, a problem happened that I discovered. My site in a page /folder. When going to this page gives error of not found. It’s because I commented on the line RewriteCond %{REQUEST_FILENAME} !-d. I had to decompress because she’s so important, then I went back to square one.

  • Change on which line ?

  • But there’s already this line down.

  • @Diegosouza I am doing the tests locally, and this ok, send me in Pastebin like this your current htaccess

  • @Diegosouza I changed again, now I tested all the possibilities here on site and this ok as we talked, changes your .htaccess for this and remember to clear the browser cache or open as private.

  • I’m sorry, but it wasn’t. It’s 500.

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.