1

I have a main domain, mydomain.com and a sub domain sub.mydomain.com.

How can I show content in sub domain from main domain? I have all the files located in folder of main domain. Whenever user hits sub.mydomain.com in address bar, the contents of main domain should be displayed. URL should not be changed. I mean it should not redirect to main domain.

Thank you.

1 Answers1

1

Let me start with saying that if you have duplicate content on your site, search engines might penalize you for it. Content should not be both available through example.com and sub.example.com.

That said, if mydomain.com and sub.mydomain.com reside on the same server, the easiest way is to configure the subdomain to use the same www-root as the normal domain. You can use something along the lines of this in your main config file:

Listen 80

NameVirtualHost *:80
<VirtualHost *:80>
  DocumentRoot /www/example1
  ServerName example.com
  DocumentRoot /www/
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot /www/example2
  ServerName sub.example.com
  DocumentRoot /www/
</VirtualHost>

If the main domain is located on a different server than the sub domain is pointing to, you can proxy the requests. You would something along the lines of this in your main config file:

<VirtualHost *:80>
  ProxyPreserveHost On
  ProxyPass / http://example.com
  ProxyPassReverse / http://example.com
  ServerName sub.example.com
</VirtualHost>

See this resource for more examples on vhost configuration.

Sumurai8
  • 20,333
  • 11
  • 66
  • 100