First, do you want domain 2 to redirect to 1 or the other way around? What your code is trying to do is redirect from 1 pro 2, like this:
http://dominio1.com.br/novo/ ====> http://dominio2.com.br
(In addition there is a typo, you wrote dominio1.pro.br
, but I'll assume your original code is correct)
In addition, the variable HTTP_HOST
does not include the path ( path ) of the request, so a query for /novo
will have host only dominio1.com.br
- and therefore will not activate its rules. To match both domain and path you would need to combine the HTTP_HOST
rule with another rule using REQUEST_URI
. I'm just quoting as an observation, because I do not think that's what you want ...
To redirect from http://dominio2.com.br
to http://dominio1.com.br/novo/
you need to do the following:
RewriteEngine on
RewriteCond %{HTTP_HOST} dominio2.com.br$ [OR]
RewriteCond %{HTTP_HOST} www.dominio2.com.br$
RewriteRule ^(.*)$ http://www.dominio2.com.br/novo/$1 [P]
An example of redirection with these rules would be:
http://www.dominio2.com.br/teste/ ====> http://dominio1.com.br/novo/teste/
Tested using this online tool .
Using the flag P
assumes that your server has mod_proxy
. An alternative if both domains are being served by the same Apache installation is the passthrough flag PT
) as described in this documentation . These techniques, if I am not mistaken, will cause the user to continue to see www.dominio2.com.br
(i.e. it is an internal redirect , not external).
However, the WordPress code will make another redirect - using only the L
flag. This will cause an external redirect, which would override the first one. In the comments you said that switching from L
to P
causes a loop redirection, but this is not necessarily Apache's fault - second this article , WordPress uses" canonical "URLs by default, and whenever it detects that the user is not using the expected URL, he tries to redirect it using the code 301
. This may or may not explain this loop (not sure, so I suggest experimenting with the passthrough option too).
WordPress does not use relative, always absolute paths. There seems to be good reason for this, according to this answer in SOen , however it is mentioned a plugin that seems to do what you need - use relative URLs, which therefore will not change the domain as seen by the user. This plugin was designed for testing - not for use in production - but given this requirement to maintain the previous domain I believe that such a solution will be required regardless of the Apache redirect solution.