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 to 2, so:
http://dominio1.com.br/novo/ ====> http://dominio2.com.br
(also there is a typo, you wrote dominio1.pro.br
, but I’ll assume your original code is correct in that sense)
In addition, the variable HTTP_HOST
does not include the path (path) of the request, so that a query to /novo
will have as host only dominio1.com.br
- and therefore will not activate your rules. To marry both domain and path you would need to match the rule of HTTP_HOST
with another rule using REQUEST_URI
. I’m just quoting as an observation, because that doesn’t seem to be what you want...
To redirect from http://dominio2.com.br
for 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 redirecting with these rules would be:
http://www.dominio2.com.br/teste/ ====> http://dominio1.com.br/novo/teste/
Tested using this online tool.
The use of flag P
assumes that your server has the mod_proxy
. An alternative if both domains are being served by the same Apache installation is passthrough (flag PT
), as described in that documentation. These techniques, if I’m not mistaken, will cause the user to continue seeing the www.dominio2.com.br
(i.e. is a redirect intern, and not external).
However, the Wordpress code will make another redirect - using only the flag L
. This will cause an external redirect, which would override the first one. In the comments you said the L
for P
causes a loop redirect, but this is not necessarily the fault of Apache - second that article, Wordpress uses "canonical" Urls by default, and whenever it detects that the user is not using the expected URL it tries to redirect it using the code 301
. That may or may not explain this loop (I’m not sure, so I suggest you experiment with the option passthrough also).
Wordpress does not use relative paths, always absolute. There seems to be good reasons for this, second that answer in Soen, however it is mentioned a plugin which seems to do what you need - use relative Urls, which therefore will not change the domain as viewed by the user. This plugin was designed for testing - and not for use in production - but given this requirement to maintain the previous domain I believe a solution like this will be necessary, regardless of the solution of redirecting Apache.
to no server now, I have no way to test. Have you tried using [L, NC] or [QSA,L] ?
– Adir Kuhn
Dude, I’d love to test it, but I have no idea what you’re talking about.. Hehe If I post the code I test it, but I don’t have server knowledge. Just don’t forget that I need to keep (or change) the Word Press code, which, from what I understand, keeps the links friendly..
– Cassio Milanelo