Forum Moderators: phranque

Message Too Old, No Replies

redirecting without changing the adress in the address bar

hiding the real location

         

petersk

11:39 am on Apr 27, 2007 (gmt 0)

10+ Year Member


Hello,

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

jdMorgan

1:12 pm on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The definition of an external redirect server response is that it tells the browser to go to a new address and ask for the originally-requested content again at that new address. When a browser sees a redirect response, it takes the "redirected-to" URL provided by the server and uses it for this subsequent request. When it does so, it changes its address bar, as it would for any normal request.

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

petersk

2:24 pm on Apr 27, 2007 (gmt 0)

10+ Year Member


jdMorgan, thank you for your answer.

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](

jdMorgan

4:22 pm on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, well so are we, because the proper way to do this depends on exactly how your host has set up the server.

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

jtara

11:07 pm on Apr 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since both sites are on the same server, why not just point the common parts of both to the same files and be done with it? You are making this much more complicated than it needs to be. You don't need any kind of rewrite. You just need Alias directives.

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.

g1smd

12:57 am on Apr 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can I ask why you want to redirect one to another?

What is it that you want to achieve?

petersk

4:37 pm on May 1, 2007 (gmt 0)

10+ Year Member



I just use one hosting (one space on the server) to host two completely different sites. Because their requirements are low, they perfectly fit togather. I have good domain names for both and want to use them. I have no problem to access the secondary site with the subdomain address, but it doesn't look good and I want to make the site popular under the 'good' name. That's all.

jtara

5:56 pm on May 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you are trying to do is probably impossible under your current hosting plan.

You will either need to get a second hosting plan for the second site, or get a hosting plan that permits you to host multiple domains using virtual hosting.

petersk

4:35 am on May 4, 2007 (gmt 0)

10+ Year Member



[SOLVED]

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]