Can conditional rewrite URLs be used depending on the user agent in ASP.NET/IIS?

On a website, I work on host content that is constantly being cleaned up and published elsewhere.

Is it possible to rewrite URLs so that ordinary users and whitelisted scanners can browse the website but block access to unidentified browsers?

+6
source share
2 answers

Yes, you can do this using the URL rewrite module (I use v2 .. but it should also work with v1.x, although v1.x does not exist for testing)

<system.webServer> <rewrite> <rules> <rule name="UserAgentRedirect" stopProcessing="true"> <match url="^(.*)$" /> <conditions> <add input="{HTTP_USER_AGENT}" pattern="(iphone|ipod)" /> </conditions> <action type="Rewrite" url="/special-page.aspx" /> </rule> </rules> </rewrite> </system.webServer> 

With the rule above, ALL requests from the iPhone or iPad (or any other browser / application that has an iphone or ipod in the user agent string) will be rewritten (internal redirection) to /special-page.aspx .

+11
source

If someone really wants to clear your content, I think it's just a matter of time until he adapts his technique to fake an allowed browser. A good feature for viewing content serving different content for each user.

+2
source

Source: https://habr.com/ru/post/892731/


All Articles