Solved

Need help with URL ReWrite in IIS 8.5

Posted on 2014-09-10
4
210 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Prologue It is often required to host multiple websites on a single instance of IIS, mostly in development environments instead of on production servers. I am sure it is not much a preferred solution on production servers but this is at least a pos…
Lync server 2013 or Skype for business Backup Service Error ID 4049 – After File Share Migration
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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