3

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>
Luckyy
  • 1,021
  • 4
  • 15
  • 29
  • I have a similar question. I have my sitemap.xml and robots.txt files in a different location. Would like to use a RewriteMap to simplify this, and only use a single rule. – Andrew Craswell Apr 25 '16 at 04:07

1 Answers1

11

This worked for me.

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