Skip to Content
Professional Microsoft IIS 8
book

Professional Microsoft IIS 8

by Kenneth Schaefer, Jeff Cochran, Scott Forsyth, Dennis Glendenning, Benjamin Perkins
November 2012
Intermediate to advanced
984 pages
27h 56m
English
Wrox
Content preview from Professional Microsoft IIS 8

Common Rules

URL Rewrite is extremely flexible and has diverse usages, but certain questions tend to come up more frequently than others. Following are some examples of common rules that you can use as a base when creating your own rules.

Redirecting Non-www to www (Canonical Hostnames)

Forcing your page to redirect from domain.com to www.domain.com is a common practice for SEO. As mentioned previously, you can use the Canonical Domain Name template to create a rule that will redirect all traffic for a website to a single URL. The following example can be placed at the server or site level. It will cause a redirect to www.localtest.me if the domain name is localtest.me:

<rule name="Redirect localtest.me to www">
   <match url=".*" />
   <conditions>
      <add input="{HTTP_HOST}" pattern="ˆlocaltest\.me$" />
   </conditions>
   <action type="Redirect" url="http://www.localtest.me/{R:0}" />
</rule>

The other common option is to reverse the direction if you prefer to drop the www from the URL:

<rule name="Redirect localtest.me from www">
   <match url=".*" />
   <conditions>
      <add input="{HTTP_HOST}" pattern="ˆwww\.localtest\.me$" />
   </conditions>
   <action type="Redirect" url="http://localtest.me/{R:0}" />
</rule>

You can test by applying the first rule and visiting http://localtest.me. Your page should redirect to http://www.localtest.me. The second rule is the opposite; it will redirect from http://www.localtest.me back to http://localtest.me.

Note
See the upcoming “Adding HTTP_PROTOCOL” section to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Professional IIS 7.0

Professional IIS 7.0

Ken Schaefer, Jeff Cochran, Scott Forsyth, Rob Baugh, Mike Everest, Dennis Glendenning

Publisher Resources

ISBN: 9781118417379Purchase book