1

Redirecting to different server but same domain. I have 2 servers on different hosts. One has domain.com and the other domain.org. domain.org has more resources. Now i want to create a sub domain on the first one (sub.domain.com) and redirect to (sub.domain.org) whiles maintaining the .com in the urls.

Thanks.

1

There are only two ways to do this, as far as I know.

To "Genuinely" keep the domain the .com, you'll need to set up a Reverse Proxy. In Apache, this is very easy.

NameVirtualHost *:80
<VirtualHost *:80>
     ServerName sub.yourdomain.com
     ProxyRequests off
     #optimally, use some sort of local URL. Saves bandwidth, faster.
     ProxyPass / http://localhost/
     ProxyPassReverse / http://localhost/
     #alternatively, use the public URL.
     #ProxyPass / http://domain.org/
     #ProxyPassReverse / http://domain.org/
</VirtualHost>

The second way is with an iFrame:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="EN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Full Page IFrame</title>
<style type="text/css">
html {overflow: auto;}
html, body, div, iframe {margin: 0px; padding: 0px; height: 100%; border: none;}
iframe {display: block; width: 100%; border: none; overflow-y: auto; overflow-x: hidden;}
</style>
</head>
<body>
<iframe id="tree" name="tree" src="`http://domain.org`" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto"></iframe>
</body>
</html>

Just know that the iFrame would be less forgiving, since Search Engines would see it differently, if SEO matters to you. Another issue is that if you have SSL, it's a totally different ballgame for both iFrames and Apache. And thirdly, if a user has some sort of web filter blocking stuff on the .org, then it will be blocked on the .com.

The Apache proxy is a better solution, in my opinion, because it puts all the content on one page. However, it would be a little slower if they are on two different servers.

2
  • how do i set up the reverse proxy? in which file? with ssh? – karto Jun 21 '12 at 13:22
  • If you have SSH access, it should likely be in the Apache config, at /etc/apache2/sites-available/(site-folder) or you can put it in the httpd.conf file. It just needs to go into the Apache config file for your site, and then don't forget to restart Apache. – ionFish Jun 21 '12 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.