Solved

Need help with URL ReWrite in IIS 8.5

Posted on 2014-09-10
4
204 Views
Last Modified: 2014-09-17
I am new to URL ReWrite. I am trying to create a rule to change
/Parts.aspx?pn=3299W-1-103
to
/Items.aspx?pn=3299W-1-103
With after "pn=" needing to be captured and applied to the rewritten URL.

I started with creating a blank rule. In the Match URL, under pattern I have "^/Parts.aspx?id=([_0-9a-z-]+)" but when I go to Test Pattern, it says the input data does not match the pattern.

If in the pattern I change it to "^/Parts.aspx([_0-9a-z-]+)" and test with "/Parts.aspx3299W-1-103" it works, but I need the "?pn=" to be there.

Any ideas or help?
0
Comment
Question by:jst3751
  • 3
4 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40315986
Here you go:

<add input="{QUERY_STRING}" pattern="(?:^|&)id=([0-9]+)(?:&|$)" /> - this condition checks if the query string contains a parameter id that has a numeric value. The actual value is captured in a condition back-reference. Note that this pattern will work even if there are other parameters on the query string.

More info on how to make this work for you:
http://www.iis.net/learn/extensions/url-rewrite-module/using-rewrite-maps-in-url-rewrite-module
0
 
LVL 1

Author Comment

by:jst3751
ID: 40319760
For the testing of the pattern, turns out I needed to use the escape character before the ?, so the pattern is actually

^/Parts.aspx\?pn=([_0-9a-z-]+)

So now testing the pattern works.

However, testing the actual website, I keep getting a 404 page not found and looking at the IIS log, it appears that the rewrite rule is not even being used.
0
 
LVL 1

Accepted Solution

by:
jst3751 earned 0 total points
ID: 40320304
OK, got this to work finally.

SIMPLIFY

On the rule for pattern to match, used

/parts.aspx

rewrite to

/items.aspx

and it works as expected.
0
 
LVL 1

Author Closing Comment

by:jst3751
ID: 40327547
Sometimes try not to overthink the problem and simplify it and go with the basics.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question