Skip to content

Commit 47f717f

Browse files
committed
Added another example covering the feedback
1 parent dd9b7d4 commit 47f717f

File tree

1 file changed

+63
-7
lines changed

1 file changed

+63
-7
lines changed

15/umbraco-cms/reference/routing/iisrewriterules.md

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,20 @@ For more details and other examples, take a look at the [URL Rewriting Middlewar
8383

8484
## Examples of rewrite rules
8585

86-
* A great site showing 10 very handy IIS Rewrite rules: [URL rewriting tips and tricks](https://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/)
87-
* Another site showing some handy examples of IIS Rewrite rules: [Some useful IIS rewrite rules](https://odetocode.com/blogs/scott/archive/2014/03/27/some-useful-iis-rewrite-rules.aspx)
88-
* If you needed to a lot of static rewrites using rewrite maps: [Rule with rewrite map rule template](https://www.iis.net/learn/extensions/url-rewrite-module/rule-with-rewrite-map-rule-template)
86+
Below are some handy IIS Rewrite Rules you can use in your projects:
8987

90-
For example, to always remove a trailing slash from the URL (make sure Umbraco doesn't add a trailing slash to all generated URLs by setting `AddTrailingSlash` to `false` in your [RequestHandler settings](../configuration/requesthandlersettings.md)):
88+
* **10 Handy IIS Rewrite Rules**
89+
A great resource showcasing 10 practical IIS Rewrite rules: [URL rewriting tips and tricks](https://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/)
90+
91+
* **Examples of IIS Rewrite Rules**
92+
Another useful collection of IIS rewrite rule examples: [Some useful IIS rewrite rules](https://odetocode.com/blogs/scott/archive/2014/03/27/some-useful-iis-rewrite-rules.aspx)
93+
94+
* **Static Rewrites Using Rewrite Maps**
95+
If you need to handle a lot of static rewrites, consider using rewrite maps: [Rule with rewrite map rule template](https://www.iis.net/learn/extensions/url-rewrite-module/rule-with-rewrite-map-rule-template)
96+
97+
### Example: Remove a Trailing Slash
98+
99+
To remove a trailing slash from the URL (ensure Umbraco does not add a trailing slash by setting `AddTrailingSlash` to `false` in your [RequestHandler settings](../configuration/requesthandlersettings.md)):
91100

92101
```xml
93102
<rule name="Remove trailing slash" stopProcessing="true">
@@ -101,7 +110,9 @@ For example, to always remove a trailing slash from the URL (make sure Umbraco d
101110
</rule>
102111
```
103112

104-
Another example would be to enforce HTTPS only on your site:
113+
### Example: Enforce HTTPS
114+
115+
To ensure your site only runs on HTTPS:
105116

106117
```xml
107118
<rule name="Redirect to HTTPS" stopProcessing="true">
@@ -114,7 +125,9 @@ Another example would be to enforce HTTPS only on your site:
114125
</rule>
115126
```
116127

117-
Another example would be to redirect from non-www to www (except for the Umbraco Cloud project hostname):
128+
### Example: Redirect Non-www to www
129+
130+
To redirect traffic from non-www to www (excluding the Umbraco Cloud project hostname):
118131

119132
```xml
120133
<rule name="Redirect to www prefix" stopProcessing="true">
@@ -128,6 +141,49 @@ Another example would be to redirect from non-www to www (except for the Umbraco
128141
</rule>
129142
```
130143

144+
### Example: Remove the .aspx Extension
145+
146+
If you want to redirect .aspx URLs to their extensionless counterparts, you can use the following rule. Make sure you also have a web.config file in the root of your site:
147+
148+
```xml
149+
<configuration>
150+
<system.webServer>
151+
<rewrite>
152+
<rules>
153+
<!-- Redirect .aspx URLs to their extensionless counterparts -->
154+
<rule name="Remove ASPX extension" stopProcessing="true">
155+
<match url="^(.*)\.aspx$" />
156+
<conditions logicalGrouping="MatchAll">
157+
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
158+
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
159+
</conditions>
160+
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
161+
</rule>
162+
</rules>
163+
</rewrite>
164+
</system.webServer>
165+
</configuration>
166+
```
167+
168+
### Example: Custom Rewrite Rules for Umbraco Cloud
169+
170+
An example configuration to help ensure your custom rules integrate properly:
171+
172+
```xml
173+
<?xml version="1.0" encoding="utf-8"?>
174+
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
175+
<location path="." inheritInChildApplications="false">
176+
<system.webServer>
177+
<rewrite xdt:Transform="Insert">
178+
<rules>
179+
<!-- Add your custom rules here -->
180+
</rules>
181+
</rewrite>
182+
</system.webServer>
183+
</location>
184+
</configuration>
185+
```
186+
131187
{% hint style="warning" %}
132-
If you use **Umbraco Cloud** check the [Rewrite Rules](https://docs.umbraco.com/umbraco-cloud/set-up/project-settings/manage-hostnames/rewrites-on-cloud) article.
188+
If you use **Umbraco Cloud**, check the [Rewrite Rules](https://docs.umbraco.com/umbraco-cloud/set-up/project-settings/manage-hostnames/rewrites-on-cloud) article.
133189
{% endhint %}

0 commit comments

Comments
 (0)