Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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'm looking to set a vhosts config so that all domains under ANY ip all point to var/www/index.php so that I can sort them from there... I'm sure this is pretty simple to do but it's hard to search google for that specific question ;)

EDIT: Sorry I wasn't originally clear but I need anything file request to go to var/www, example: would request index.php...

share|improve this question
up vote 2 down vote accepted

That would be what the standard Apache config does! No need for any vhosts at all, just a basic config listening on port 80 without specifying the IP address to listen on.

share|improve this answer
And in your index.php, you can sort them out with $_SERVER['SERVER_NAME'], because the vhost name will be in there. – blauwblaatje Aug 6 '09 at 10:32
I've just tried this and although any domain/sub points to index file, when I try and do it says file not found. I need everything to go to index.php. – zuk1 Aug 7 '09 at 11:49
As explained below by Boohbah, mod rewrite will add the final piece for you. – Bart B Aug 12 '09 at 11:08
You can simply make lol.php to be a symlink to index.php too, no need for mod_rewrite IMHO – drAlberT Aug 12 '09 at 19:12
Using mod_alias is another alternative – drAlberT Aug 12 '09 at 19:12

You must set this in your apache config:

NameVirtualHost *:80

The FIRST vhost definition in your apache config is the one it falls back to if none of the others match. I have a config file called (they are included sorted by filename on CentOS 5).


I have something like this as the first Vhost:

<VirtualHost *:80>
    DocumentRoot /var/www/html/Default/
    UseCanonicalName on
    CookieTracking on

and there you can handle anything.

share|improve this answer

You can redirect requests for lol.php to index.php using a mod_rewrite rule. First, enable mod_rewrite.


LoadModule rewrite_module modules/

(This part varies depending on your OS.)

mod_rewrite for Ubuntu:

# a2enmod rewrite && /etc/init.d/apache2 force-reload

The create an .htaccess file in your DocumentRoot.

#.htaccess code
RewriteEngine On
RewriteRule ^(.*)\.php$ index.php [L]
share|improve this answer
This server is going to be getting upwards of 50k hits/day.. I've heard modrewrite decreases performance and I'd rather avoid that, can I just put the rule in vhosts? – zuk1 Aug 10 '09 at 11:27
Not if you want to redirect lol.php to index.php. – phuzion Aug 11 '09 at 12:06
50k hits is not a lot. The impact of the rewrite rule would be negligible. – skraggy Aug 11 '09 at 17:38
Another option would be to set index.html as your error page for 404s - total hack, and it would result in a return code of 404 rather than 200 - but if you really want to avoid mod rewrite, that would do it. Though, like skraggy says, with only 50k hits I doubt you have anything to worry about with mod rewrite - unless your server is very very old and crappy of course :) – Bart B Aug 12 '09 at 11:06

Your Answer


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

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