0

I've got some PDF files sitting out on a web server, and for the time being I would like to hide them (i.e. have them return 404s). Can this be accomplished in the web.config file with a Rewrite Rule?

In Apache you can do this with something like this:

RewriteRule \.pdf$ - [R=404,L,NC]

How do I accomplish the same effect with IIS?

soapergem
  • 9,263
  • 18
  • 96
  • 152

1 Answers1

1

One way to achieve this is using the HiddenSegments in IIS. HiddenSegments would make URLs inaccessible to clients. Also, IIS will return an HTTP 404 error to the client and log the 404.8 HTTP substatus.

<configuration>
   <system.webServer>
      <security>
         <requestFiltering>
            <hiddenSegments>
               <add segment="pathofpages" />
            </hiddenSegments>
         </requestFiltering>
      </security>
   </system.webServer>
</configuration>

EDIT 1: You can also use RequestFiltering to Deny the PDF extension for the clients. HttpStatus sub code 404.7would be returned. All requests for PDF files will be denied.

From IIS.net

In the Request Filtering pane, click the File Name Extensions tab, and then click Deny File Name Extension... in the Actions pane.

Abhinav Galodha
  • 9,293
  • 2
  • 31
  • 41