IIS重定向问题:含.axd路径请求返回500内部服务器错误
Fix IIS Rewrite Rule to Return 500 for .axd Paths
Hey there, let's sort out this IIS rewrite rule issue. You want requests containing .axd paths to return a 500 Internal Server Error, while all other sub-prefixed requests keep forwarding to your internal server as usual. Here's how to make that happen:
Step 1: Add a Priority Rule to Block .axd Requests
IIS processes rewrite rules top-to-bottom, so we need to add a rule that catches .axd requests first and stops further processing. This way, those requests never reach your internal server—they get the 500 response immediately.
Add this rule before your existing isite rewrite rule:
<rule name="Block AXD Requests with 500" enabled="true" stopProcessing="true"> <!-- Matches any sub-prefixed URL ending with .axd --> <match url="^sub.*\.axd$" /> <!-- Return a custom 500 response --> <action type="CustomResponse" statusCode="500" statusReason="Internal Server Error" statusDescription="The server encountered an unexpected condition that prevented it from fulfilling the request." /> </rule>
Breakdown of key parts:
^sub.*\.axd$: The regex targets URLs starting withsuband ending with.axd—this aligns with your existing rule's scope to avoid blocking unrelated.axdrequests.stopProcessing="true": Ensures once this rule matches, no subsequent rules (like your rewrite rule) run for that request.CustomResponse: Tells IIS to send a 500 status code instead of rewriting the URL.
Step 2: Keep Your Existing Rewrite Rule
Leave your original rule in place, just make sure it comes after the new block rule:
<rule name="isite rewrite" enabled="true" stopProcessing="false"> <match url="sub.*" /> <action type="Rewrite" url="http://{MY_INTERNAL_SERVER}:8383/{R:0}"/> </rule>
Step 3: Verify the Setup
- Try accessing a
.axdURL likehttp://sub.site.com/WebResource.axd?d=VulAtfIQPaLvaSxP9LTeiyvvAmd8FbIf6Q9ixGIp...—you should get a 500 error right away. - Test any other
sub-prefixed URL (e.g.,http://sub.site.com/your-page)—it should still forward tohttp://{MY_INTERNAL_SERVER}:8383/sub.your-pageas expected.
内容的提问来源于stack exchange,提问作者Shay Hakshorian
相关产品推荐
相关产品推荐

