Forum Discussion
Convert Microsoft rewrite rules to iRule
Hello,
I would like to convert Microsoft rewrite rules to iRule :
<rewrite>
<rules>
<rule name="rule1" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions trackAllCaptures="true" logicalGrouping="MatchAll">
<add input="{HTTP_USER_AGENT}" pattern="(google|bot|spider|pinterest|crawler|archiver|flipboardproxy|mediapartners|facebookexternalhit|insights|quora|whatsapp|slurp)" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="https://www.domain.com{REQUEST_URI}" appendQueryString="false"/>
</rule>
<rule name="rule2" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions trackAllCaptures="true" logicalGrouping="MatchAll">
<add input="{HTTP_FROM}" pattern=".+" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="https://www.domain.com{REQUEST_URI}" appendQueryString="false"/>
</rule>
</rules>
</rewrite>
Regards,
Thierry
- Andrew-F5
Employee
Thierry,
I'll admit I'm no Microsoft expert so here's my best attempt so far for rule1:
# <rule name="rule1" stopProcessing="true"> # <match url=".*" ignoreCase="true" /> # <conditions trackAllCaptures="true" logicalGrouping="MatchAll"> # <add input="{HTTP_USER_AGENT}" pattern="(google|bot|spider|pinterest|crawler|archiver|flipboardproxy|mediapartners|facebookexternalhit|insights|quora|whatsapp|slurp)" /> # <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> # </conditions> # <action type="Rewrite" url="https://www.domain.com{REQUEST_URI}" appendQueryString="false"/> # </rule> # when HTTP_REQUEST { if {[matchclass [HTTP::header "User-Agent"] equals bot_datagroup] && ![[HTTP::uri] contains "."]}{ HTTP::respond 301 Location https://www.domain.com[HTTP::uri] } }
This rule requires you create a datagroup on the F5 titled 'bot_datagroup', the rule does a string match to see if the User-Agent header matches any of the entries listed in the 'bot_datagroup' datagroup and checks if the URI does not contain a dot (.) as some means to see if it's a file being referenced.
The bot datagroup would contain the following strings: google, bot, spider, pinterest, crawler, archiver, flipboardproxy, mediapartners, facebookexternalhit, insights, quora, whatsapp, slurp.
If you can clarify a bit what your expectation is for the F5 I could probably clean the rule up significantly.
- Andrew-F5
Employee
For those interested what the rules look like in IIS.
- Thierry_John
Nimbostratus
Thank you for this answer.
But I don't want to redirect to specified URL, I want to rewrite URL.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com