Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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: sub.domain.com/lol.php would request index.php...

share|improve this question

3 Answers 3

up vote 2 down vote accepted
+75

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 domain.com/lol.php 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 –  AlberT Aug 12 '09 at 19:12
    
Using mod_alias is another alternative –  AlberT 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).

/etc/httpd/conf.d/000-Default-webhoster.basjes.nl.conf

I have something like this as the first Vhost:

<VirtualHost *:80>
    DocumentRoot /var/www/html/Default/
    ServerName webhoster.basjes.nl
    UseCanonicalName on
    CookieTracking on
    CookieDomain .basjes.nl
</VirtualHost>

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.

httpd.conf:

LoadModule rewrite_module modules/mod_rewrite.so

(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
1  
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

 
discard

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.