Reputation: 19484
I have website with multiple domains and i want them to have different robots.txt I have rule for this so depends on domain request it will return different robots. This is workin beta slot but after deploy to production slot its not working.
<rule name="robots" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="^robots.txt" />
</conditions>
<action type="Rewrite" url="https://{HTTP_HOST}/{HTTP_HOST}.robots.txt" />
</rule>
If i am changing action type to redirect it seems to work because webbrowser redirects and is in stuck with to many redirects (Which make sense.)
Upvotes: 0
Views: 1242
Reputation: 18465
As url-rewrite-module-configuration-reference mentioned that the server variable REQUEST_URI
can be used to access the entire requested URL path, including the query string. Assuming that the URL for robots.txt is https://<your-hostname-and-port>/robots.txt
, then you would get the string /robots.txt
as an input via REQUEST_URI
.
<rewrite>
<rules>
<rule name="robots" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" ignoreCase="true"/>
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="^/robots.txt" />
</conditions>
<action type="Rewrite" url="{HTTP_HOST}.robots.txt"/>
</rule>
</rules>
</rewrite>
With the rule above, I could rewrite my URL and get the following result:
Changing the type of the rule action from Rewrite to Redirect, I could get the following result:
Upvotes: 2