I have a subdomain loja.meusite.com.br and I need traffic to be redirected to meusite.com/loja maintaining the original URL loja.meusite.com.br, via htacces
I tried that. It redirects correctly but does not maintain the original URL "loja.meusite.com.br".
I need to access "meusite.com/loja", keeping the URL "loja.meusite.com.br" in the browser
Options +FollowSymLinks
RewriteEngine on
Options +MultiViews
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^loja.meusite.com.br$ [OR]
RewriteCond %{HTTP_HOST} ^www.loja.meusite.com.br$
RewriteRule (.*)$ http://www.meusite.com/loja$1 [R=301,L]
OK, that means you have two options: 1. you can use an internal reverse proxy or 2. you can simply setup the target http host ("domain") such that it shares the physical file system with those other hosts. Or map both using a symbolic link in the file system. As said the first option means a performance penalty, the second depends on the environment you actually have, so how much you are in control of the system the http server is operated on.
1: using the proxy module (again: note that the proxy module and the proxy http module need to be loaded and enabled, which is not the case with typicl cheap hosting providers):
You either directly use the proxy module in the actual http server's host configurtion:
ProxyRequests off
ProxyPass / http://www.meusite.com/loja/
ProxyPassReverse / http://www.meusite.com/loja/
Or you use the proxy module embedded in the rewriting module:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)loja\.meusite\.com\.br$
RewriteRule ^ http://www.meusite.com/loja%{REQUEST_URI} [P]
2: you can setup the DOCUMENT_ROOT
of the http hosts "loja.meusite.com.br" and "www.loja.meusite.com.br" (probably a "ServerAlias" of the former) such that it contains a symlink in the file system which points to the DOCUMENT_ROOT
of the http host "www.meusite.com". Depending on the actual logic you implemented in that host this might already be enough.
The advantage: you do not require a second, internal http request for each and every incoming request. But you need to sort out that your application logic gets along with those requests...