Let's say my main site is www.mySite.com
. The path is:
/home/itsme/public_html/
I want to set up a staging server at staging.mySite.com
which redirects to:
/home/itsme/public_html/staging
Can I do this with a CNAME to make it happen?:
staging CNAME www.mySite.com/staging.
Or will that fail because the destination is not a root domain?
This will not work.
A CNAME record in DNS makes an alias of one domain name for another, and has no connection to any other part of a url.
What you can do is use a CNAME or just multiple A records in DNS to make sure both addresses point at the same machine and then on that machine configure your webserver to enable multiple virtual hosts responding to the different names.
How you do this will vary depending on the webserver software you're running. How to do it with Apache is described in the Apache docs on Virtual Hosts.
Okay. Well you have a lot of possible solutions to such a deployment process.
What Don wrote is a nice one. If you're using Apache Virtual Hosts make it very easy to host multiple independant sites on on IP, but its only handy if you can control your DNS or wanna apply your local static host configuration (/etc/hosts or %SystemRoot%\system32\drivers\etc\hosts).
You have to understand how HTTP works. I don't know how deep you're into that. Just in a short: The idea is to create a new domain, prefixed for example, just like "test.YOURDOMAIN.COM" and let it have its completely own directory, not a subdir. If you make an entry to your HOSTS file on your client, you can use your browser to access that web site actually on your server, that does not really host that domain but with that hosts configuration your browser will ask for the testing domain and retrieve those files if you configured your server correctly. In your case (actually you seem to have DNS access) you can leave the hosts-file part out, because maybe you really can configure your own subdomains.
That approach is nice, because you can switch easily - immediately without service interruption or side effects (enable/disable sites, reconfigure apache). You won't have to mess around with directories and create perhaps insane filesystem states if access is not disabled, services get unavailable... a mess for a heavy load site - or if you wanna maintain service quality - the better way.
So if you wanna do it this way, and you have an apache, you would...
For a Debian GNU/Linux Server Environment and can give you more detailed hints. RHEL derivates I don't have enough experiences.