How to redirect the old domain to the new one? [duplicate]

-3

I would like to redirect the old domain to the new one, in the current code looping is occurring infinite.

Follow my code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Options +FollowSymLinks
RewriteRule (.*) http://novodominio.tk$1 [R=301,L]
</IfModule>
    
asked by anonymous 29.02.2016 / 22:56

1 answer

2

This is wrong, the bar is missing:

  RewriteRule (.*) http://novodominio.tk$1 [R=301,L]

That's right:

 RewriteRule (.*) http://novodominio.tk/$1 [R=301,L]

I recommend adding a rule to prevent infinite redirection like this:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Options +FollowSymLinks

#verifica se já está no novo dominio (não adicione http: na frente)
RewriteCond %{HTTP_HOST} !adota-me.tk$ [NC]

#redireciona
RewriteRule (.*) http://adota-me.tk/$1 [R=301,L]

A tip, it is preferable not to use IfModule in the case of mod_rewrite only, because if the server is not enabled for mod_rewrite then you will not notice the error and it will appear to be a problem in .htaccess when the problem is other, if I remove the <IfModule mod_rewrite.c> and </IfModule> , and after this try to run the .htaccess on a server with mod_rewrite disabled it will issue the error:

  

Internal Error Server

This means that you need to enable mod_rewrite, so follow the instructions in this link:

Or contact support for your hosting

    
29.02.2016 / 23:17