We help IT Professionals succeed at work.

URL REWRITING IS NOT WORKING ON IIS7

Hi, I was using URL Rewriting feature on my website.It was working fine on IIS6 Until I switched my computer on Windows7 and hosted on IIS7. Its not working on IIS7.I checked couple of articles and tried adding rule on IIS7 for URL Rewriting, But the solution I got  was adding static URLS.like
/Books/Book1_Details.aspx  and changed to /Books/BookDetails.aspx?TITLE=Book1.
In above scenario I had to add many rule for each link and I don't want that.
      Previously I was using dynamic rules which used to work for many links ons IIS6 code was like that:
<rewriter>
            <rewrite url="~/Books/(.+)_Details.aspx" to="~/Studies/BooksDetails.aspx?TITLE=$1" />
      </rewriter>

 and with all bookids it was working on IIS6,Please tell me how to generate dynamic URL mapping on IIS7.

Regards,
Sudhanshu
Comment
Watch Question

Most Valuable Expert 2012
Top Expert 2014

Commented:
What do you mean by not working? Are you getting any errors?

Is the issue similar to one discussed here?

http://improve.dk/making-url-rewriting-on-iis7-work-like-iis6/

Author

Commented:
I already tried above link but it did not work. I am attaching screenshot.

Regards,Sudhanshu
Error.jpg
Dan McFaddenSystems Engineer

Commented:
If you have many URLs that must be rewritten like the Books section above, you should work with rewrite maps and then can use a generic rewrite rule to process requests against the map.

link:  http://www.iis.net/learn/extensions/url-rewrite-module/using-rewrite-maps-in-url-rewrite-module

Dan

Commented:
Your question doesn't seem to be consistent:

/Books/Book1_Details.aspx  and changed to /Books/BookDetails.aspx?TITLE=Book1.
             <rewrite url="~/Books/(.+)_Details.aspx" to="~/Studies/BooksDetails.aspx?TITLE=$1" />

Which is the correct one? Books to Books? Or Books to Studies?
Also, try to send another error screenshot WITH the url bar?

Author

Commented:
Sorry its <rewriter>
            <rewrite url="~/Books/(.+)_Details.aspx" to="~/Books/BooksDetails.aspx?TITLE=$1" />
      </rewriter>

Author

Commented:
Hi Dan,I already seen that link but could not see generic way there.

Commented:
You said it's Books to Books, but clearly your error screenshot shows Studies.
Dan McFaddenSystems Engineer

Commented:
Really?

Follow the steps in the first section that define the URLs to setup.  For example, your Book URL in this post.

After the first section is a subtitle called "Referencing a rewrite map from rewrite rule."  There the author explains what this piece of configuration structure does:  <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)">

The above "add" tells IIS to look into the rewrite map called "StaticRewrites" and fulfill the request based on the URL maps defined there.

Dan

Author

Commented:
Hi Dan its hard to understand for me But i will try.Basically previously I was using like that
<rewriter>
            <rewrite url="~/Studies/(.+)_Details.aspx" to="~/Studies/StudyDetails.aspx?TITLE=$1" />
      </rewriter>

My URL were rewriting  like that
From     /Studies/Retort_P_Details.aspx
To         /Studies/StudieDetails.aspx?Title=Retort_P

  Please tell me how I can use this thing in your mentioned link.
Dan McFaddenSystems Engineer

Commented:
First, as per the article, you create an URL map.  Using your 2 examples:

<rewrite>
    <rewriteMaps>
        <rewriteMap name="StaticRewrites" defaultValue="">
            <add key="~/Books/(.+)_Details.aspx" value="~/Studies/BooksDetails.aspx?TITLE=$1" />
            <add key="~/Studies/(.+)_Details.aspx" value="~/Studies/StudyDetails.aspx?TITLE=$1" />
        </rewriteMap>
    </rewriteMaps>
</rewrite>

Open in new window


Then you create the actual generic rewrite rule:

<rules>
    <rule name="Rewrite Rule">
        <match url=".*" />
        <conditions>
            <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
        </conditions>
        <action type="Rewrite" url="{C:1}" />
    </rule>
</rules>

Open in new window


Both of these items are created via the IIS Manager, as per the article.

Dan

Author

Commented:
Hi Dan I tried this But still its not working.If i give static URL then it works.Here is web.config change:
 <rewrite>
      <rewriteMaps>
        <rewriteMap name="StaticRewrites" defaultValue="">
          <add key="/Studies/(.+)_Details.aspx" value="/Studies/StudyDetails.aspx?TITLE=$1" />
        </rewriteMap>
      </rewriteMaps>
      <rules>
        <rule name="Rewrite Rule">
          <match url=".*" />
          <conditions>
            <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
          </conditions>
          <action type="Rewrite" url="{C:1}" />
        </rule>
      </rules>
    </rewrite>

Author

Commented:
Hi Dan if i set it like   <add key="/Studies/(.+)_Details.aspx" value="/Studies/StudyDetails.aspx?TITLE=$1" />
  Then it does not work

But below works
 <add key="/Studies/Retort_Pouches_Details.aspx" value="/Studies/StudyDetails.aspx?Title=Retort_Pouches" />

Author

Commented:
Hi Dan I am waiting for your reply.If any one can help,Please do.
Dan McFaddenSystems Engineer

Commented:
OK, let's back up a bit.

First, the error image you posted stated that a resource (page) did not exist.  This has nothing to do with URL rewriting.  Does the page that the error refers to exist?

Dan

Author

Commented:
Hi Dan,It was example of how error coming on IIS7.Yes it was error because URL Rewriting was not rendering. Please let me know if you have any question.

Sudhanshu
Systems Engineer
Commented:
OK... its hard to work off indirect information when trying to help someone troubleshoot a real issue.

Then let's go back to the start.  Remove any rewrite rules or rewrite maps on the site.  Trying testing a rule like this:

<rewrite>
    <rules>
        <rule name="rewrite STUDIES section" stopProcessing="true">
            <match url="^Studies\/(.+)_Details\.aspx" />
            <action type="Redirect" url="/Studies/StudyDetails.aspx?Title={R:1}" />
        </rule>
    </rules>
</rewrite>

Open in new window


This should work for IIS7+.  I have tested it on a IIS8 server and it worked without errors.

Dan

Author

Commented:
Hi Dan,Thanks for reply.Your solutions seems to work on my machine,I am using Windows7. Basically I had to first install URL Rewriting for IIS7 using this link.
http://www.microsoft.com/en-in/download/details.aspx?id=7435
   Now I tried to set up this on server machine,Basically using Windows Server 2008,When I tried to install same,Then I am getting error "Installation Package not supported by this Processor,Please contact your vendor."
Please tell me which URL rewriter can be installed on Windows server 2008.

  Then I checked more and found its 32bit server,Then I downloaded URL Rewriting from this link
http://www.microsoft.com/en-in/download/details.aspx?id=5747
 and it installed fine.But When i gone to INETMGR and selected my site,it not showing in that option like it showing my side(locally).
Do I need to restart server side IIS so URL Rewrite option will display?

    I checked more and just copied pasted that URL REWRITE section on my server and it started working fine there too.My question is,Is URL Rewrite installation necessary?

Sudhanshu
Dan McFaddenSystems Engineer

Commented:
Sudhanshu: yes, to use URL Rewrite on IIS it needs to be installed.  Otherwise IIS will not know what to do with the Rewrite section of the web.config and just ignore it.

As for what URL Rewrite package to install on Server 2008... what processor architecture is the server, 32 or 64 bit?

I would do an IISRESET just as a safety precaution.

Dan

Author

Commented:
Hi Dan,What is IISRESET and it's executed via? Window Server 2008 was using 32bit so i installed 32bit URL Rewrite. Please tell me what I need to do so IIS website can start showing URL Rewrite option.

Sudhanshu
Dan McFaddenSystems Engineer

Commented:
From a command prompt, type:  IISRESET and hit enter

Here is reference link on using the IIS Manager and the URL Rewrite module:

link:  http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

If an IISRESET doesn't seem to resolve the issue, try rebooting the server.

Dan

Author

Commented:
Hi Dan.My issue resolved.