How to point subdomain to different directory ?

Hello everyone,

I've tried to search and read through the forums here, but I can't seem to find an answer for what I'm trying to do.

I don't think it is that complicated, just seems that I am missing something.

What I want to do, is have a subdomain point to a different directory.

For example, I want to set it up like this:

www.mydomain.com –> points to --> /var/www/mydomain_live

dev.mydomain.com --> points to --> /var/www/mydomain_dev

I've tried following the guide in the linode docs section the best I could, but I'm not a networking expert so it seems that I am missing something.

I'm not concerned about mail or anything like that, just the web addresses resolving to their respective directories.

the main domain, www.mydomain,com, is directing to the correct place. The subdomain is what I am having problems with.

Currently what I have done is this (per the linode docs section):

  • Created files in the "sites-available" for each website, and put the following into the files:

/etc/apache2/sites-available/www.mydomain.com

# Admin email, Server Name (domain name), and any aliases

ServerAdmin my@email.com

ServerName www.mydomain.com

commented this out as unsure if need here

ServerAlias mydomain.com

Index file and Document Root (where the public files are located)

DirectoryIndex index.php

DocumentRoot /var/www/mydomain_live

Log file locations

LogLevel warn

ErrorLog /var/www/mydomainlive/log/error.log

CustomLog /var/www/mydomainlive/log/access.log combined

/etc/apache2/sites-available/dev.mydomain.com

# Admin email, Server Name (domain name), and any aliases

ServerAdmin my@email.com

ServerName dev.mydomain.com

commented this out as unsure if need here

ServerAlias mydomain.com

Index file and Document Root (where the public files are located)

DirectoryIndex index.php

DocumentRoot /var/www/mydomain_dev

Log file locations

LogLevel warn

ErrorLog /var/www/mydomaindev/log/error.log

CustomLog /var/www/mydomaindev/log/access.log combined

I then navigated to each doc root for each site, and made a symlink:

(I'm assuming I was supposed to do this from the directory which will be each sites root)

  • Navigate to /var/www/mydomain_live

a2ensite www.mydomain.com

  • Navigate to /var/www/mydomain_dev

a2ensite dev.mydomain.com

And then restarted Apache, etc.

In the linode dns manager, I originally had just created the mydomain.com, with the default records etc.

I then added an A/AAAA record for dev.mydomain.com

So my "zone file" looks like this:

@ IN SOA ns1.linode.com. my.email.com. 2012092803 14400 14400 1209600 86400

@ NS ns1.linode.com.

@ NS ns2.linode.com.

@ NS ns3.linode.com.

@ NS ns4.linode.com.

@ NS ns5.linode.com.

@ MX 10 mail.mydomain.com.

@ A 123.456.789.000

dev A 123.456.789.000

mail A 123.456.789.000

www A 123.456.789.000

At this point I really don't know what is missing, like I said I imagine it's something simple but I have no clue.

If anyone out there would be able to point my in the right direction, I would be very grateful.

This is an ubuntu lamp stack, just the typical setup that is created using the LAMP stack scripts, on a linode 512, if that makes a difference.

Thanks in advance for any replies.

1 Reply

Edit - Nevermind, there was a stray htacess file in one of the directories that was causing the problem, the above configuration works as it should.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct