简体   繁体   中英

IIS URL Rewrite Rule Ignored when Path is Part of Virtual Directory

I'm attempting to create a URL rewrite rule in IIS that redirects a user to a new web page. The path for the rule is a deleted PDF file that was contained in a virtual directory. I have this rule working on an existing site, but on our new/updated website using.Net core - the rule does not work (returns a 404 status code). The virtual directory setup is the same - /pdf. It appears that the rule is completely ignored if it is a virtual directory.

Website
│   New_Web_Page
└───pdf (virtual directory)
│   │   A_PDF_File.pdf
<rule name="PDF Redirect Rule" stopProcessing="true">
  <match url="pdf/A_PDF_File.pdf" />
  <action type="Redirect" url="New_Web_Page" redirectType="Permanent"  />
</rule>

Placing a web.config file within the virtual directory with the appropriate rewrite rule fixes the issue. The rule will need to be changed to match the placement of the file. The rule is:

<rule name="PDF Redirect Rule" stopProcessing="true">
  <match url="A_PDF_File.pdf" />
  <action type="Redirect" url="/New_Web_Page" redirectType="Permanent"  />
</rule>

And the directory now looks like this:

Website
│   New_Web_Page
└───pdf (virtual directory)
│   │   A_PDF_File.pdf
│   │   web.config

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM