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 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?

Thanks

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
add comment

2 Answers

up vote 0 down vote accepted

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

RewriteEngine On
RewriteBase /

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

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

share|improve this answer
add comment

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
add comment

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.