How can I disable php scripts on a specific subdir of my website using IIS7?
I have a wordpress blog and I want to disable php on the "uploads" dir.
How can I disable php scripts on a specific subdir of my website using IIS7?
I have a wordpress blog and I want to disable php on the "uploads" dir.
You have quite a few options here. All code examples (one for each approach) need to be placed in web.config file in your "uploads" folder (in case if you do not know this).
1) Remove handler that is responsible for processing *.php files (in IIS Manager it is "Handler Mappings"):
Cons:
2) Using Request Filtering module disable all requests to files with
.php
extension -- server will send 404.7 error to the client. This module is bundled with IIS 7.5, but for IIS 7.0 you may need to download and install Administration Pack.If you have more than one extension for PHP you will need to list them as well (e.g.
.phtml
,.php5
etc).3) Using URL Rewrite module create a rule to Abort such request.
.phtml
,.php5
etc).4) Using URL Rewrite module create a rule to respond with custom error instead of processing such request.
5) Using URL Rewrite module create a rule to redirect to your own error page for all of such requests.
The above rule will internally redirect (rewrite) such requests to a
404.php
file in the website root folder (e.g.http://www.example.com/404.php
)Use #2 if possible -- it will be executed before URL Rewrite step which will be beneficial on very busy server.
I know this thread is a little old, but I personally subscribe to the "Write + Execute = BAD" school of thought, and therefore a upload folder should never execute. With this in mind, any handler beyond the static file handler could be considered a security risk.
To remove all but the static file handler (regardless of what the other handlers are called) (all the benefits of #1 in the above, but without the Cons):