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

Asked

Viewed 570 times

0

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

Examples are: www.dominio.com.br/folder www.dominio.com.br/pasta/noticia/nome-da-noticia www.dominio.com.br/folder/contact.php www.dominio.com.br/folder/tag/tag-name www.dominio.com.br/folder/jobs.php

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

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

1 answer

1


Create a directory called "folder" in Documentroot where are the files pages of www.dominio.com.br ("/var/www/html", "/opt/site/" etc) and within it create the file ". htaccess" with the following content:

<IfModule mod_rewrite.c>

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

</IfModule>

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

  • So I did a test like this: www.dominio.com.br/folder/subfolder redirected the address to: www.dominio.com.br/subfolder

  • So it worked?

  • No! I was supposed to go home.

  • 1

    Remove the "$1" from the end, it is it that complements the URL. I had understood that you also wanted to translate the accesses.

  • It worked out! Thank you so much.

Browser other questions tagged

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