I have a mail server which hosts email for multiple domains and provides webmail services. For each of the domains, an A record (mail.domain-name.com) has been created which points to this server. The server runs the Apache web server. How can I serve a different default web page (like index.html) for each of the host names without configuring virtual hosts ? The idea is to let the users land on a domain specific welcome page which would then give them link to the common web mail interfaces and other services on the server. For example,

http://mail.domain1.com/ should serve index1.html

http://mail.domain2.com/ should serve index2.html

http://mail.domain3.com/ should serve index3.html

and so on where these pages are under the same Document Root.


  • WHY do you not want to use virtual hosts ? That sounds like a broken design requirement. – adaptr Jan 28 '13 at 15:18

Instead of using index.html, use a server-side scripting language (like PHP) index page. The script can detect the host name used from the HTTP headers and display the proper information.

For PHP, the variable you need is $_SERVER['HTTP_HOST']

Alternatively, you can follow Apache's docs to create dynamic virtual hosts using rewrite rules. Here's their example:

RewriteEngine on

RewriteMap    lowercase int:tolower

RewriteCond   ${lowercase:%{HTTP_HOST}}   ^www\.([^.]+)\.example\.com$
RewriteRule   ^(.*) /home/%1/www$1
  • Thanks. Is there a way to achieve this using Apache configuration ? – catman Jan 28 '13 at 14:52
  • Yes. Virtual hosts. But you specifically asked to not use that. – longneck Jan 28 '13 at 15:11
  • Oh! Re-write rules! See my edit! – longneck Jan 28 '13 at 15:12
  • I created an index.php page with a switch statement using the $_SERVER['HTTP_HOST'] variable as suggested by you and used header statements to redirect the page host name wise and its working perfectly. Thanks. – catman Jan 29 '13 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.