homepage Welcome to WebmasterWorld Guest from 54.198.94.76
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Best Practice CNAME's
username




msg:4086813
 1:44 am on Feb 25, 2010 (gmt 0)

Hi all,

I am setting up a website, which will have different CNAMES. i.e:

client1.test.com
client2.test.com

Not having much experience with this before, I want to find out the best practice for serving different content once the browser detects client1.test.com, as oppose to client2.test.com once I have set the CNAME records in my host providers control panel.

I have been advised that .htaccess can point these urls to different holding folders, i.e. instead of client1 serving the generic content the index for that page may sit in the www.test.com/client/ directory. Is this how CNAME's are supposed to be setup, or have I missed the general idea.

Thanks in advance.

 

jdMorgan




msg:4086866
 4:25 am on Feb 25, 2010 (gmt 0)

The first question is why are you using CNames instead of simply using an 'A' record, which is faster on DNS lookup.

The purpose of a CName is that it is an alias -- It points to another domain's DNS record, possibly on a different DNS server, so that it serves as a 'soft link' to the IP address defined in that other DNS record. If the pointed-to DNS record is changed, no change in the CNAME record is required. However, the other result is that clients (e.g. browsers and search robots) have to do two DNS requests to find the IP address to which the current HTTP request should be sent (assuming that this DNS lookup isn't already cached locally).

The disposition of hostname requests (resolving them to a specific filespace on a server) is unrelated to their DNS configuration, so the one really has nothing to do with the other. Therefore, the answer to "What's the best practice?" is "Do whatever you like with them."

Your purpose for defining "client1" and "client2," not some aspect of the DNS configuration, should drive your decisions.

If you have server config access privileges, the best approach (assuming that you're hosting client (customer) sites here) is to set up individual VirtualHosts for each client, and keep these clients' files in completely-separate filespaces.

Lacking config access, then yes, .htaccess can be used to resolve requests for different hostnames to different subdirectories (or to the same subdirectory, if desired). However either way, there is nothing to keep client 1 from examining/modifying client 2's files if FTP access is granted to these clients. Therefore, their site security is non-existent with this model.

See the Apache "virtual hosting" tutorials for more information of virtual hosts, and see the "mass virtual hosting" example in the Apache URL Rewriting Guide for an example of the ".htaccess method."

There are also scores (if not hundreds) of previous threads on this subject posted here, findable using a site search for "rewrite subdomain subdirectory" and similar. Add "RewriteCond HTTP_HOST" to the search keywords to further narrow that search to mod_rewrite methods.

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved