Forum Moderators: phranque
my goal is to redirect http://mysite-1.com to http://mysite-1.myothersite.com, so that the address in the browser's address bar doesn't change.
I have a redirect that works:
RewriteCond %{HTTP_HOST} ^.*mysite-1.com$ [NC]
RewriteRule ^(.*)$ http://mysite-1.myothersite.com/$1 [R=301,L]
but in this case the user sees that the site mydomain-1 is hosted on a subdomain of myothersite.
Could you help me with better solution?
Regards, Peter
So no, there is no way to do a redirect that does not change the address bar.
An internal rewrite can be used to change what file is served in response to a URL request. But this only works within a single server -- or more accurately, within the filespace of a single 'account' on the server. It cannot be used to "change domains" unless the two domains reside in the same server filespace.
It is possible that you might solve the problem by using the 'visible' domain as a proxy for the 'real' domain using a "reverse proxy" configuration. See Apache mod_proxy [httpd.apache.org]. The two main problems with this are that all requests and responses for the back-end domain must pass through the server for the front-end domain, and that most inexpensive shared hosting accounts can't be configured to do this.
Again, read through the Apache mod_proxy documentation, paying attention to the discussion of "Reverse proxies" -- You don not need, and should not implement a forward proxy, as this is a major security liability.
Jim
Both sites are on the same server, the one in the root dir (/www/mydomain.com/www/root), the other in a subdomain (/www/mydomain.com/subdomain/root).
In betweeen I have read alot on this topic and have tried without the R=301, so that the server does the so called 'internal rewriting', but had no success. The address still changes.
I have tried with [P], also without luck, it returns 404 Not Found.
Now I am completely lost :[smilestopper](
It could be as simple as a rewriterule in the subdomain or alternate domain targeting "/path-to-main-domain-files" where "/" takes you to the "top" of the directory structure. But on some hosts, this won't work because of the way the alternate domain and its document root directory are defined.
All you can really do is experiment. If it doesn't work, then figure out another way to do what you want (like SymLink-ing all the files from the main domain into the alternate's space) or just drop the idea of having two domains for the same thing, because this splits and therefore dilutes the PageRank and link-popularity of *both* sites -- and it may not be useful for users, either.
Jim
If the sites are running as different Linux users, you may have to do some fiddling with file permissions to make sure that the directories and files are accessible from both users.
O.K. Thanks for all your replies!
As jdMorgan says, this is possible only within the filespace of a single 'account' on the server, within the root directory of a single domain and not even in higher directories within the same account. So the solution is to do a symbolic link (in my case named 'v1') from the root directory to the subdomain, and then use mod_rewrite like this to redirect:
RewriteEngine on
RewriteBase /
######## example.com ########
RewriteCond %{HTTP_HOST} ^.*example.com$ [NC]
RewriteCond /www/quux-foo.com/www/root/v1%{REQUEST_URI} -d
RewriteRule ^(.*[^/])$ %{REQUEST_FILENAME}/ [L]
RewriteCond %{HTTP_HOST} ^.*quux-foo.com$ [NC]
RewriteCond %{REQUEST_URI} ^/v1/
RewriteRule ^(.*)$ - [F]
RewriteCond %{HTTP_HOST} ^.*example.com$ [NC]
RewriteCond /www/quux-foo.com/www/root/v1%{REQUEST_URI} -f [OR]
RewriteCond /www/quux-foo.com/www/root/v1%{REQUEST_URI} -d
RewriteRule ^(.*)$ v1/$1 [L]
RewriteCond %{HTTP_HOST} ^.*example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/v1/
RewriteRule ^(.*)$ v1/index.php [L]
######## example.com ########
[edited by: jdMorgan at 5:06 am (utc) on May 4, 2007]
[edit reason] Examplified [/edit]