Skip to content

Commit f1cd8a1

Browse files
authored
Merge pull request #6711 from umbraco/rewrite
Added an example to IIS rewrites article
2 parents 202d8b2 + c34e8f8 commit f1cd8a1

File tree

5 files changed

+263
-24
lines changed

5 files changed

+263
-24
lines changed

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

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,17 @@ 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/)
86+
### External Resources
87+
88+
If you are looking for additional inspiration or examples for creating IIS Rewrite rules, these external resources are a great starting point:
89+
90+
* A great site showing 10 handy IIS Rewrite rules: [URL rewriting tips and tricks](https://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/)
8791
* 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)
8892
* 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)
8993

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)):
94+
### Example: Remove a Trailing Slash
95+
96+
The following rule removes any trailing slashes from the URL.
9197

9298
```xml
9399
<rule name="Remove trailing slash" stopProcessing="true">
@@ -101,7 +107,11 @@ For example, to always remove a trailing slash from the URL (make sure Umbraco d
101107
</rule>
102108
```
103109

104-
Another example would be to enforce HTTPS only on your site:
110+
Ensure Umbraco does not add a trailing slash by setting `AddTrailingSlash` to `false` in your [RequestHandler settings](../configuration/requesthandlersettings.md).
111+
112+
### Example: Enforce HTTPS
113+
114+
The following rule ensures your site only runs on HTTPS:
105115

106116
```xml
107117
<rule name="Redirect to HTTPS" stopProcessing="true">
@@ -114,7 +124,9 @@ Another example would be to enforce HTTPS only on your site:
114124
</rule>
115125
```
116126

117-
Another example would be to redirect from non-www to www (except for the Umbraco Cloud project hostname):
127+
### Example: Redirect Non-www to www
128+
129+
The following rule redirects traffic from non-www to www (excluding the Umbraco Cloud project hostname):
118130

119131
```xml
120132
<rule name="Redirect to www prefix" stopProcessing="true">
@@ -128,6 +140,49 @@ Another example would be to redirect from non-www to www (except for the Umbraco
128140
</rule>
129141
```
130142

131-
{% 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.
143+
### Example: Remove the .aspx Extension
144+
145+
The following rule redirects `.aspx` URLs to their extensionless counterparts.
146+
147+
```xml
148+
<configuration>
149+
<system.webServer>
150+
<rewrite>
151+
<rules>
152+
<!-- Redirect .aspx URLs to their extensionless counterparts -->
153+
<rule name="Remove ASPX extension" stopProcessing="true">
154+
<match url="^(.*)\.aspx$" />
155+
<conditions logicalGrouping="MatchAll">
156+
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
157+
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
158+
</conditions>
159+
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
160+
</rule>
161+
</rules>
162+
</rewrite>
163+
</system.webServer>
164+
</configuration>
165+
```
166+
167+
### Example: Custom Rewrite Rules for Umbraco Cloud
168+
169+
An example configuration to help ensure your custom rules integrate properly:
170+
171+
```xml
172+
<?xml version="1.0" encoding="utf-8"?>
173+
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
174+
<location path="." inheritInChildApplications="false">
175+
<system.webServer>
176+
<rewrite xdt:Transform="Insert">
177+
<rules>
178+
<!-- Add your custom rules here -->
179+
</rules>
180+
</rewrite>
181+
</system.webServer>
182+
</location>
183+
</configuration>
184+
```
185+
186+
{% hint style="info" %}
187+
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.
133188
{% endhint %}

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

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,17 @@ 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/)
86+
### External Resources
87+
88+
If you are looking for additional inspiration or examples for creating IIS Rewrite rules, these external resources are a great starting point:
89+
90+
* A great site showing 10 handy IIS Rewrite rules: [URL rewriting tips and tricks](https://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/)
8791
* 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)
8892
* 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)
8993

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)):
94+
### Example: Remove a Trailing Slash
95+
96+
The following rule removes any trailing slashes from the URL.
9197

9298
```xml
9399
<rule name="Remove trailing slash" stopProcessing="true">
@@ -101,7 +107,11 @@ For example, to always remove a trailing slash from the URL (make sure Umbraco d
101107
</rule>
102108
```
103109

104-
Another example would be to enforce HTTPS only on your site:
110+
Ensure Umbraco does not add a trailing slash by setting `AddTrailingSlash` to `false` in your [RequestHandler settings](../configuration/requesthandlersettings.md).
111+
112+
### Example: Enforce HTTPS
113+
114+
The following rule ensures your site only runs on HTTPS:
105115

106116
```xml
107117
<rule name="Redirect to HTTPS" stopProcessing="true">
@@ -114,7 +124,9 @@ Another example would be to enforce HTTPS only on your site:
114124
</rule>
115125
```
116126

117-
Another example would be to redirect from non-www to www (except for the Umbraco Cloud project hostname):
127+
### Example: Redirect Non-www to www
128+
129+
The following rule redirects traffic from non-www to www (excluding the Umbraco Cloud project hostname):
118130

119131
```xml
120132
<rule name="Redirect to www prefix" stopProcessing="true">
@@ -128,6 +140,49 @@ Another example would be to redirect from non-www to www (except for the Umbraco
128140
</rule>
129141
```
130142

131-
{% 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.
143+
### Example: Remove the .aspx Extension
144+
145+
The following rule redirects `.aspx` URLs to their extensionless counterparts.
146+
147+
```xml
148+
<configuration>
149+
<system.webServer>
150+
<rewrite>
151+
<rules>
152+
<!-- Redirect .aspx URLs to their extensionless counterparts -->
153+
<rule name="Remove ASPX extension" stopProcessing="true">
154+
<match url="^(.*)\.aspx$" />
155+
<conditions logicalGrouping="MatchAll">
156+
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
157+
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
158+
</conditions>
159+
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
160+
</rule>
161+
</rules>
162+
</rewrite>
163+
</system.webServer>
164+
</configuration>
165+
```
166+
167+
### Example: Custom Rewrite Rules for Umbraco Cloud
168+
169+
An example configuration to help ensure your custom rules integrate properly:
170+
171+
```xml
172+
<?xml version="1.0" encoding="utf-8"?>
173+
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
174+
<location path="." inheritInChildApplications="false">
175+
<system.webServer>
176+
<rewrite xdt:Transform="Insert">
177+
<rules>
178+
<!-- Add your custom rules here -->
179+
</rules>
180+
</rewrite>
181+
</system.webServer>
182+
</location>
183+
</configuration>
184+
```
185+
186+
{% hint style="info" %}
187+
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.
133188
{% endhint %}

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

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,17 @@ 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/)
86+
### External Resources
87+
88+
If you are looking for additional inspiration or examples for creating IIS Rewrite rules, these external resources are a great starting point:
89+
90+
* A great site showing 10 handy IIS Rewrite rules: [URL rewriting tips and tricks](https://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/)
8791
* 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)
8892
* 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)
8993

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)):
94+
### Example: Remove a Trailing Slash
95+
96+
The following rule removes any trailing slashes from the URL.
9197

9298
```xml
9399
<rule name="Remove trailing slash" stopProcessing="true">
@@ -101,7 +107,11 @@ For example, to always remove a trailing slash from the URL (make sure Umbraco d
101107
</rule>
102108
```
103109

104-
Another example would be to enforce HTTPS only on your site:
110+
Ensure Umbraco does not add a trailing slash by setting `AddTrailingSlash` to `false` in your [RequestHandler settings](../configuration/requesthandlersettings.md).
111+
112+
### Example: Enforce HTTPS
113+
114+
The following rule ensures your site only runs on HTTPS:
105115

106116
```xml
107117
<rule name="Redirect to HTTPS" stopProcessing="true">
@@ -114,7 +124,9 @@ Another example would be to enforce HTTPS only on your site:
114124
</rule>
115125
```
116126

117-
Another example would be to redirect from non-www to www (except for the Umbraco Cloud project hostname):
127+
### Example: Redirect Non-www to www
128+
129+
The following rule redirects traffic from non-www to www (excluding the Umbraco Cloud project hostname):
118130

119131
```xml
120132
<rule name="Redirect to www prefix" stopProcessing="true">
@@ -128,6 +140,49 @@ Another example would be to redirect from non-www to www (except for the Umbraco
128140
</rule>
129141
```
130142

131-
{% 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.
143+
### Example: Remove the .aspx Extension
144+
145+
The following rule redirects `.aspx` URLs to their extensionless counterparts.
146+
147+
```xml
148+
<configuration>
149+
<system.webServer>
150+
<rewrite>
151+
<rules>
152+
<!-- Redirect .aspx URLs to their extensionless counterparts -->
153+
<rule name="Remove ASPX extension" stopProcessing="true">
154+
<match url="^(.*)\.aspx$" />
155+
<conditions logicalGrouping="MatchAll">
156+
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
157+
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
158+
</conditions>
159+
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
160+
</rule>
161+
</rules>
162+
</rewrite>
163+
</system.webServer>
164+
</configuration>
165+
```
166+
167+
### Example: Custom Rewrite Rules for Umbraco Cloud
168+
169+
An example configuration to help ensure your custom rules integrate properly:
170+
171+
```xml
172+
<?xml version="1.0" encoding="utf-8"?>
173+
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
174+
<location path="." inheritInChildApplications="false">
175+
<system.webServer>
176+
<rewrite xdt:Transform="Insert">
177+
<rules>
178+
<!-- Add your custom rules here -->
179+
</rules>
180+
</rewrite>
181+
</system.webServer>
182+
</location>
183+
</configuration>
184+
```
185+
186+
{% hint style="info" %}
187+
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.
133188
{% endhint %}

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

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,17 @@ 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/)
86+
### External Resources
87+
88+
If you are looking for additional inspiration or examples for creating IIS Rewrite rules, these external resources are a great starting point:
89+
90+
* A great site showing 10 handy IIS Rewrite rules: [URL rewriting tips and tricks](https://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/)
8791
* 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)
8892
* 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)
8993

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)):
94+
### Example: Remove a Trailing Slash
95+
96+
The following rule removes any trailing slashes from the URL.
9197

9298
```xml
9399
<rule name="Remove trailing slash" stopProcessing="true">
@@ -101,7 +107,11 @@ For example, to always remove a trailing slash from the URL (make sure Umbraco d
101107
</rule>
102108
```
103109

104-
Another example would be to enforce HTTPS only on your site:
110+
Ensure Umbraco does not add a trailing slash by setting `AddTrailingSlash` to `false` in your [RequestHandler settings](../configuration/requesthandlersettings.md).
111+
112+
### Example: Enforce HTTPS
113+
114+
The following rule ensures your site only runs on HTTPS:
105115

106116
```xml
107117
<rule name="Redirect to HTTPS" stopProcessing="true">
@@ -114,7 +124,9 @@ Another example would be to enforce HTTPS only on your site:
114124
</rule>
115125
```
116126

117-
Another example would be to redirect from non-www to www (except for the Umbraco Cloud project hostname):
127+
### Example: Redirect Non-www to www
128+
129+
The following rule redirects traffic from non-www to www (excluding the Umbraco Cloud project hostname):
118130

119131
```xml
120132
<rule name="Redirect to www prefix" stopProcessing="true">
@@ -128,6 +140,49 @@ Another example would be to redirect from non-www to www (except for the Umbraco
128140
</rule>
129141
```
130142

131-
{% 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.
143+
### Example: Remove the .aspx Extension
144+
145+
The following rule redirects `.aspx` URLs to their extensionless counterparts.
146+
147+
```xml
148+
<configuration>
149+
<system.webServer>
150+
<rewrite>
151+
<rules>
152+
<!-- Redirect .aspx URLs to their extensionless counterparts -->
153+
<rule name="Remove ASPX extension" stopProcessing="true">
154+
<match url="^(.*)\.aspx$" />
155+
<conditions logicalGrouping="MatchAll">
156+
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
157+
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
158+
</conditions>
159+
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
160+
</rule>
161+
</rules>
162+
</rewrite>
163+
</system.webServer>
164+
</configuration>
165+
```
166+
167+
### Example: Custom Rewrite Rules for Umbraco Cloud
168+
169+
An example configuration to help ensure your custom rules integrate properly:
170+
171+
```xml
172+
<?xml version="1.0" encoding="utf-8"?>
173+
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
174+
<location path="." inheritInChildApplications="false">
175+
<system.webServer>
176+
<rewrite xdt:Transform="Insert">
177+
<rules>
178+
<!-- Add your custom rules here -->
179+
</rules>
180+
</rewrite>
181+
</system.webServer>
182+
</location>
183+
</configuration>
184+
```
185+
186+
{% hint style="info" %}
187+
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.
133188
{% endhint %}

0 commit comments

Comments
 (0)