URL Rewrite for Developers
Introduction to URL Rewrite
Scott Forsyth
weblogs.asp.net/owscott
@scottforsyth
scott@vaasnet.com
Goals for this Course
Create
Work with
your own
URL Parts
rules
Edit
Optimize
Regular
your site
Expression
for SEO
Rules
Intended Audience
Developer or Administrator
URL Rewrite URL Rewrite
Beginner Intermediate
Course Overview
Introduction to URL Rewrite
Rule Templates
Understanding URL Parts
Regular Expressions and Back-References
Common Rules
Further Considerations
Troubleshooting URL Rewrite
URL Rewriting in IIS vs. ASP.NET
URL Rewrite in
IIS
URL Rewriting
in MVC or
WebForms
URL Rewriting in ASP.NET MVC
routes.MapRouteLowercase(
"HomeIndex",
"",
new { controller = "Home", action = "Index" }
);
routes.MapRouteLowercase(
"HomeContact",
"contact",
new { controller = "Home", action = "Contact" }
);
URL Rewrite in IIS
<rule name="Reports redirect" enabled="false" stopProcessing="true">
<match url="^city/reports(/|$)" />
<action type="Redirect" url="http://{HTTP_HOST}/city/reports.aspx"
redirectType="Temporary" />
<conditions>
<add input="{URL}" pattern="^/city/reports\.aspx$"
negate="true" />
</conditions>
</rule>
Types of Rules
1. Redirect
2. Rewrite
3. Off-server Rewrite (reverse proxy)
4. Server Variables Rewrite
5. Outbound Rewrites
Types of Rules
1. Redirect
2. Rewrite
3. Off-server Rewrite (reverse proxy)
4. Server Variables Rewrite
5. Outbound Rewrites
Redirect Rule Examples
Non-www to www redirect
Enforcing trailing slashes or forcing to lowercase
Mapping of old to new URLs after site redesign, or for SEO
Creating a “Down For Maintenance” page
Types of Rules
1. Redirect
2. Rewrite
3. Off-Server Rewrite (reverse proxy)
4. Server Variables Rewrite
5. Outbound Rewrites
Rewrite Rule Examples
Front a legacy URL with a friendly one
Remapping 3rd level domain information to the query string
Running a site from a subfolder
Types of Rules
1. Redirect
2. Rewrite
3. Off-Server Rewrite (reverse proxy)
4. Server Variables Rewrite
5. Outbound Rewrites
Off-Server Rewrite (Reverse Proxy) Example
Front a legacy URL with a friendly one
Note: Requires that ARR be installed
Types of Rules
1. Redirect
2. Rewrite
3. Off-Server Rewrite (reverse proxy)
4. Server Variables Rewrite
5. Outbound Rewrites
Server Variable Rules Example
Locking parts of your site to particular IP addresses
Changing HTTP host headers on the way through
Types of Rules
1. Redirect
2. Rewrite
3. Off-Server Rewrite (reverse proxy)
4. Server Variables Rewrite
5. Outbound Rewrites
Outbound Rewrite Examples
Changing URLs in a page to a more friendly URL
Catching client-side redirects and rerouting them
Installing URL Rewrite
Works on IIS7 and later
Windows 8.5
Windows
Windows 8 Server 2008
(+R2)
Windows
Windows 7 Server 2012
(+R2)
Windows Future
Vista Versions
For IIS6
For IIS6