Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subdomain to subdirectory

Status
Not open for further replies.

jenvillarreal

Technical User
Jun 14, 2002
2
US
I have a website that I want a subdomain to go to a subdirectory of the main site. For example, I want sub.mydomain.com to go to mydomain.com/sub.

I have the subdomain working, but it just goes to the main site. I know I need a DNS entry in the zone file, and I did that by making an A record and pointing it to the IP of the main site like this:

$ORIGIN mydomain.com.
mail IN A 123.12.123.123
ftp IN A 123.12.123.123
www IN A 123.12.123.123
sub IN A 123.12.123.123


I also made a VirtualHost entry in the http.conf file that looks like this:

<VirtualHost sub.mydomain.com>
User myuser
Group mygroup
ServerName sub.mydomain.com
ServerAdmin webmaster@mydomain.com
DocumentRoot /home/mydir/mydomain-TransferLog /home/mydir/mydomain-logs/access-log
ScriptAlias /cgi-bin/ /home/mydir/mydomain-</VirtualHost>

I am obviously doing something wrong. Can someone please help me out! Thanks in advance, -Jenn.
 
Since you have the same ip for everything, you need to use name based addressing. Do this by uncommenting this line:

#NameVirtualHost *

Then change <VirtualHost sub.mydomain.com> to:

<VirtualHost *>

You will also need to create a container for your main server. If you use one vhost in apache, you have to make everything a vhost. The default will be the 1st one defined. Make sure you use the ServerName directive in each container.
 
One more thing. You will need to change UseCanonicalName On to Off. Some distros need this in each container
 
I am nervous about changing settings that will then apply to everyone. We are a small hosting company with a couple hundred accounts listing in the http.conf file. If I change that will it affect anyone else? Also, I searched the file for #NameVirtualHost * and it is no where in the file. Should I add it? Thanks, sorry for being such a pain. -Jenn.
 
If you have a couple hundred domains on your server, then you shouldn't have to change a thing. There is no reason you can't have a sub-domain defined the same way as a domain. There is no law that says a sub-domain has to be under the domain's DocumentRoot. You can have it next to it just as the other domains. Wullie brought up a good point in a thread a couple weeks back that seemed to be easier than creating a container for each domain then having to reboot the server every time you changed httpd.conf. You might take a look at it here thread65-285214 . I hope you find the answer to your problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top