Score:1

IIS URL REWRITE 404 FOR FILE TYPE

es flag

I have a directory of avatar images that some avatars have been deleted to clear space. What is an IIS URL Rewrite that can redirect images not found in a directory or by file extension of .jpg to default.jpg

Score:0
cn flag

I am not sure about the URL Rewrite module being helpful here, but you can try the following:

In the directory with all your images create a new web.config file:

 <?xml version="1.0" encoding="UTF-8"?>
 <configuration>
   <system.webServer>
          <httpErrors errorMode="Custom">
            <remove statusCode="404" subStatusCode="-1" />
             <error statusCode="404" path="https://my.coolsite.com/images/404avatar.png" responseMode="Redirect" />
         </httpErrors>
   </system.webServer>
 </configuration>

You are telling IIS to redirect to an existing image in case an image in this directory is not found.

I don't like the idea that we have to use an absolute URL here, but the other options for error pages (Insert Content and Execute URL) did not work for me.

You can do the same in the UI, select the directory and choose Error Pages then edit the 404 entry to Respond with a 302 redirect

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.