URL rewrite module 2.0

Discussion in 'Site Programming, Development and Design' started by Michael, May 13, 2010.

  1. We recently upgraded to version 2.0 of the IIS 7 URL rewrite module. Microsoft has included templates that make the URL rewrite process much easier than it has been in the past. These are essentially tiny wizards that allow you to plug in a couple values and let the tool do the rest.

    The first thing you will have to do is get the IIS 7 Manager add-in to control the service. When you connect to the server using IIS 7 Manager you will be prompted to install the add-in (if you already have the old module you will be asked to upgrade when you connect).

    Example 1:

    Redirect requests for HostingAccountDomain.com to www.HostingAccountDomain.com
    • In IIS 7 Manager, navigate to the "URL Rewrite" section
    • Click "Add Rule" on the right hand side
    • Click the canonical domain name template
    • Enter your domain name, including the www
    That's it. Really. You're finished.

    Example 2:

    User-friendly URLs.

    Let's assume for a moment that we have an application that generates URLs in the following manner:
    And you want to rewrite the URL as:
    In IIS 7 Manager, navigate to the URL Rewrite section
    • Click "Add Rule" on the right side
    • Click "User-Friendly URL"

    You will notice that you have an option for how you want the URL to be rewritten. URL rewrite 2.0 will generate the regular expressions and inbound/outbound rules required to perform the task automatically.

    Another cool feature is that by clicking the "Create corresponding outbound rewrite rule" check box, any links with an unfriendly URL within your pages will also be rewritten.

    So let's say you had a page with the following link:
    <a href="Test">http://www.HostingAccountDomain.com/app/index.aspx?id=123">Test Link</a>​
    This link would automatically be rewritten on the fly and served up as:
    <a href="Test">http://www.HostingAccountDomain.com/123">Test Link</a>​

    You can see how easily URL Rewrite 2.0 addresses these common scenarios. But much more complicated rewriting is also possible. If you want to work with some of the more complex operations, visit the learning section of the IIS site.
     
    Last edited: Oct 14, 2015
  2. finally!

    this is what I've been waiting for. thanks!
     
  3. Good deal, glad it works for you.
     
  4. Is there a way to point a domain to a differnt subfolder using the rewrite module

    I have mydomain.com and I want it to point to /folder instead of the root. I'm still learning about this module, but it seems like a waste to have to do the redirect programmatically.
     
  5. Ray

    Ray

  6. I've been scavenging for information about how to write a rewrite (not redirect) rule to remove a subdomain from a request.

    I have a rule like the following, which uses a subdomain as a 'shortcut' to a deeper folder, and simply appends the rest of the path and querystring.

    <rule name="UCD">
    <match url="^(.*)" />
    <conditions>
    <add input="{HTTP_HOST}" pattern="^(?!www)sub\.domain\.net$" />
    </conditions>
    <action type="Rewrite" url="/facebook/Utility/{R:1}" />
    </rule>

    The point of this is to hide the full path to the 'root' directory of the subdomain to browsers.

    The above works correctly for the most part, except for resources URI's defined with "~/some/file.css" (really just css and js files). A site without js and css files sucks!

    So, I'm looking for a way to write a rule that does the following...
    Request: sub.domain.net/Some/Path
    Rewritten: domain.net/other/values/long/path/Some/Path (subdomain gone + path exnted). By setting a condition to only affect urls with the subdomain it 'should' not destroy relative URIs...

    Any ideas?
     
  7. Ray

    Ray

    Do you have a specific subdomain name?

    Try using the pattern ^subdomain.domain\.net$

    I'm not sure if you want to capture all subdomain names and point it to a specific subfolder.
     
  8. Yes, I have specific subdomain names.

    For using the pattern you suggested would work to match the pattern, however, I'm looking to rewrite the subdomain away.

    From what I can tell, if you specify a fully qualified url in the action tag the Url Rewrite module actually returns a redirect. Not specifying a fully qualified Url in the action only rewrites the path and query string.

    I'm trying to rewrite "ucd.jharkness.net" to "jharkness.net/Facebook/Utility/Ucd/".
    I can append/modify the path just fine, but can't for the life of me figure how to change the host (drop subdomain) without a redirect.
     
  9. Ray

    Ray

    Use the pattern I gave you and for the Rewrite rule use...

    /Facebook/Utility/Ucd/{R:1} and that should redirect and rewrite the URL to jharkness.net/Facebook/Utility/Ucd/.... Isn't that what you are looking to do?
     

Share This Page