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 setting up a virtual host in apache just for static files. Therefore I'd not add a php handler, which is fine.

However, is it possible to configure the virtualhost to accept only jpg, gif and png requests or at least throw 404's for any php file request?


share|improve this question
Why can't you just remove the php module from apache? Do you have other dynamic sites you need it for? – Yitzchak Jul 21 '11 at 17:14
up vote 0 down vote accepted

Well .. try this (you will need mod_rewrite enabled):

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST}
RewriteRule ^(.*)\.php - [NC,F,L]

This will block (403 error) all requests to .php files if domain name = If you do not like 403 error -- replace [F] flag by [R=404].

share|improve this answer

Yes - there's lots of ways of doing it. But why do you need to return a 404 response if it tries to

1) access a file which should not exist on the server in the first place

2) has no handler


share|improve this answer
I'm trying to set up a seperate domain for my static files, pointing to the same docroot directory as my main domain. This only to avoid cookies being sent for statics – Steven De Groote Jul 21 '11 at 16:45

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.