Skip to content

Instantly share code, notes, and snippets.

@parasdaryanani
Created June 14, 2022 08:22
Show Gist options
  • Save parasdaryanani/abe4241196304026a68fe77b9366367f to your computer and use it in GitHub Desktop.
Save parasdaryanani/abe4241196304026a68fe77b9366367f to your computer and use it in GitHub Desktop.
Rewrite /news/t/todays-headlines as /news/todays-headlines
<system.webServer>
<!-- paste the following before the </system.webServer> closing tag -->
<rewrite>
<rules>
<rule name="UsePrettyUrls" stopProcessing="true">
<match url="^news/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="news?t={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
@parasdaryanani
Copy link
Author

This UrlRewrite rule lets you create user friendly URLs that remove query params. For example, in this case when the user visits /news/todays-headlines the page content actually loads from /news?t=todays-headlines or news/t/todays-headlines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment