How to redirect a page using .htaccess?

3

How have you been? Well, I've been dealing with a problem that is summarized in the following:

I want through the .htaccess file to redirect just the home page from my site to another domain. Example:

Redirect: www.site1.com - > www.site2.com.br

If you have other pages in that same domain ( Example : www.site1.com / domain), you should not redirect to the second domain (www.site2. com.).

    
asked by anonymous 11.12.2018 / 23:25

1 answer

3

With php you can put in your index as follows:

$siteAtual = str_replace(["www.", "http://", "https://"], "", $_SERVER['HTTP_HOST']);
if($siteAtual == "meusite.com" && $_SERVER['REQUEST_URI'] == "/"){
    header("Location: http://www.novosite.com.br");
}
  • $ _ SERVER ['HTTP_HOST'] - takes the primary URL
  • $ _ SERVER ['REQUEST_URI'] - get what you have after the main URL

If what is later is empty, it redirects the citizen.

    
12.12.2018 / 00:04