Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


I have a community and every user can has its own subdomain at my project e.g.

In PHP I use the variable HTTP_HOST to determinate the username (username1).


Let the user route it's own domain to his subdomain by CNAME record. should link to


After adding the CNAME Record ( the HTTP_HOST variable should return instead of

How can I fix this issue? Hope somebody can help me, please.

Current Virtual Host Setting

    <VirtualHost *:80>
    DocumentRoot /home/webapps/egoapp/current/public
          <DirectoryMatch  /\.git/|/\.svn/ >
           Deny from all
         <Directory "/home/webapps/egoapp/current">
          Options FollowSymLinks
          AllowOverride All
          Order allow,deny
          Allow from all

     RewriteEngine On

     # Enable status page for monitoring purposes                               
     RewriteCond %{REMOTE_ADDR} ^(                                    
     RewriteRule ^(/server-status) $1 [H=server-status,L]                       

     # Redirects to a maintenance page if the specified file below exists       
     # ...but it still allows images to be served                               
     RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f                    
     RewriteCond %{SCRIPT_FILENAME} !/system/maintenance.html                   
     RewriteCond %{SCRIPT_FILENAME} !^(.+).(gif|png|jpg|css|js|swf)$            
     RewriteRule ^.*$ /system/maintenance.html [L]           

     # Proxy the rest to the load balancer
     RewriteRule ^/(.*)${REQUEST_URI} [P,QSA,L]

     # Setup the logs in the appropriate directory
     CustomLog /var/log/httpd/access_log combined
     #ErrorLog  /var/log/httpd/error_log

     #Remote logging -- handle by syslog
     ErrorLog "|logger -p -t httperror"
     CustomLog "|logger -p -t http" combined

     LogLevel warn

     # Deflate
     AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
     BrowserMatch ^Mozilla/4 gzip-only-text/html
     BrowserMatch ^Mozilla/4.0[678] no-gzip
     BrowserMatch bMSIE !no-gzip !gzip-only-text/html
     SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0

Ideas for solving this problem

I think I have to edit the /etc/resolv.conf, but I don't know how ;) After Playing a little bit I can change the Servername to or "undefinded domain" but not to

Current Resov.conf

search eu-west-1.compute.internal

share|improve this question
up vote 1 down vote accepted

The HTTP_HOST variable is created from the actual URI request that the client sent to your virtual host. This actually has nothing to do with your DNS, it's just a string, so editing your resolv.conf will not help. At the point that the client is connecting to the server and providing that HTTP_HOST, it has already done the work of resolving DNS and determining which IP address it wants to send the request to for that URI.

I think your easiest solution would be to store the association between and username1 in a database of some kind and compre the HTTP_HOST variable to the database to determine which user's site to return.

Your only other option would be to manually configure new virtualhosts for each of these domains. This can be time consuming and error prone, I would go with a database driven method that could be integrated into your site and would be relatively automated.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.