Rewriting sitemap.xml url - asp.net web.config

3k Views Asked by At

I know in htaccess but how can I rewrite url of sitemap using web.config Rules property. I have tried following ways, but none worked

<rule name="sitemap URL" patternSyntax="ECMAScript" stopProcessing="true">
    <match url=".*" />
    <conditions>
      <add input="{HTTP_HOST}" pattern="^/sitemap.xml$" /> - Not working
      <add input="{HTTP_HOST}" pattern="^domain.com/sitemap.xml$" /> - Not working
      <add input="{HTTP_HOST}" pattern="^www.domain.com/sitemap.xml$" /> - Not working
    </conditions>
    <action type="Rewrite" url="foldername/sitemaps/sitemap-a.xml"  />
  </rule>

also tried

<rule name="sitemap URL" patternSyntax="ECMAScript" stopProcessing="true">
    <match url="^.+\.(local|www)?(domain).+\.(?:xml)$" />
    <action type="Rewrite" url="foldername/sitemaps/sitemap-a.xml"  />
  </rule>
1

There are 1 best solutions below

1
On

This worked for me.

<rule name="SiteMap" patternSyntax="Wildcard" stopProcessing="true">
    <match url="sitemap.xml" />
    <action type="Rewrite" url="sitemap.ashx" appendQueryString="false" />       
</rule>