How to do a redirect via .htaccess from a subdomain to the main domain?

0

I have a domain (www.dominio.com.br) and a subfolder (www.dominio.com.br/pasta) and would like to redirect all the links of this folder to the domain.

Examples: www.dominio.com.br/pasta www.dominio.com.br/pasta/noticia/nome-da-noticia www.dominio.com.br/pasta/contato.php www.dominio.com.br/pasta/tag/nome-da-tag www.dominio.com.br/pasta/trabalhos.php

All requested links in the "folder" with and without extension, I want to redirect them to the main domain.

How do I? And where do I put the .htaccess file?

    
asked by anonymous 26.03.2018 / 17:02

1 answer

1

Create a directory called "folder" in the DocumentRoot where www.dominio.com pages are located ("/ var / www / html" / opt / site / "etc) and inside it create the" .htaccess "file with the following content:

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /
    RewriteRule ^(.*)$ http://www.dominio.com.br/$1

</IfModule>

In this case ALL , ^(.*)$ in REGEX, which arrives at link will be redirected to link ; the $ 1 at the end is just the rest of the URL ("index.html", "admin.php", "post / 2018/03/26" etc).

    
26.03.2018 / 17:28