1

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

  • 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

2 Answers2

1

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

?

symcbean
  • 21,009
  • 1
  • 31
  • 52
  • 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
0

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].

LazyOne
  • 3,064
  • 1
  • 18
  • 16