简体   繁体   中英

IIS URL Rewrite and ARR don't handle rewrite rule properly

I have a problem with some understanding of how the URL Rewrite and ARR work together. I have a site and a standalone service that generates and provides updated sitemaps for the site. Below is my rule to handle sitemap requests. It is a local rule in the web.config under sites directory (the site is hosted under IIS 10).

<rule name="Sitemap Rule" stopProcessing="true">
      <match url="^sitemap.*" />
      <action type="Rewrite" url="http://sitemap.mysitedomain/provider?key={R:0}" logRewrittenUrl="true" />
</rule>

All looks good but it doesn't work. The only response I've got is 404. I should note that the ARR module is active and it properly handles other proxy requests.

To be transparent on this rule imagine that some web-robot request http://mysitedomain/sitemap.xml and the real request will be served from the http://sitemap.mysitedomain/provider?key=sitemap.xml where sitemap.mysitedomain is hosted on different servers and different environment.

The strange things here is that if I put empty sitemap.xml to the root of mysitedomain all my requests to the sitemap.xml start working as expected and I started to get updated sitemap.xml from sitemap service and an empty one that I've placed to the root of the site.


Added some tracing info from failed request

For the failed requests I have next in the tracing file

...
ModuleName    RewriteModule

HeaderName    X-Original-URL 
HeaderValue   /sitemap.xml 
Replace       true 

OldUrl       /sitemap.xml 
NewUrl       http://sitemap.mysitedomain/v1/sitemap/provider?key=sitemap.xml

...

ModuleName            ApplicationRequestRouting 
Notification          MAP_REQUEST_HANDLER 
fIsPostNotification   false 
...
OldUrl                http://sitemap.laf24.ru/v1/sitemap/provider?key=sitemap.xml 
NewUrl                /sitemap.xml 

...

ModuleName            ManagedPipelineHandler 
Notification          EXECUTE_REQUEST_HANDLER 
HttpStatus            404 
HttpReason            Not Found 
HttpSubStatus         0 
ErrorCode             The operation completed successfully. (0x0) 

I should point again that if I place an empty sitemap.xml to the root of mysitedomain, than all start working as expected. I got actual data from sitemap.mysitedomain.

I have found why it is happen and it is not a problem with Url Rewrite or ARR modules. The main reason is that ASP.Net handle such requests and return 404 because there are no routes defined to process such paths.

To fix this we added ignore definitions for sitemaps urls

routes.IgnoreRoute("sitemap.xml");
routes.IgnoreRoute("sitemap/{*pathInfo}");

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