We help IT Professionals succeed at work.

IIS 10 - URL Rewrite Rule for Search Query, not working?

Hello, All.
(The development is done in ASP Classic (VB), in case I need to do something within the code.)

In the website, our search string is displayed as such.
Main.asp?Type=Results&Submit=Search&Term=KISS&Cat=3

Our URL Rewrite is this.

Pattern: Search/([_0-9a-z-(-)-,-]+)/([_0-9a-z-(-)-,-]+)
Rewrite URL: Main.asp?Type=Results&Submit=Search&Term={R:1}&Cat={R:2}

Screenshot of the RULE
URLRewrite
How can I make the Search Query work, so that when you click search, it rewrites the URL to this?

Search/KISS/3

Thanks.
Wayne
Comment
Watch Question

Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT

Commented:
your URL Rewrite rule worked well for me.

what's the exact issue you're facing right now?

so that when you click search, it rewrites the URL to this?

if you mean to change form posting action URL based on user's inputs?
Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:

When I click search, the URL does not get re-written.
It stays with the same URL


Main.asp?Type=Results&Submit=Search&Term=KISS&Cat=3



Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:

Here is the search box.


<form action="//192.168.2.12/Main.asp">
<input type="hidden" name="Type" value="Results">
<table style="text-align:left; vertical-align:top;">
<tbody><tr>
  <td style="border:1px #000000 dotted; font-size:12px;">Search<br />
  <input type="submit" name="Submit" value="Search" tabindex="3">
<input name="Term" type="text" tabindex="1" width="200" value="KISS" onBlur="javascript:if (this.value == '') this.value = 'Search';" onFocus="javascript:if (this.value == 'Search') this.value='';">
<br />
<select class="FormUnits" name="Cat" tabindex="2">
<option value="3">Artist</option>
</select>
</td></tr>
</tbody></table>
</form>

Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT

Commented:
When I click search, the URL does not get re-written.
It stays with the same URL


    Main.asp?Type=Results&Submit=Search&Term=KISS&Cat=3

I think you need to edit the HTML instead. Can you share us the source code of your form's action? or click event ?
Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:

Well, I do not like how the new CODE block works on EE.
It messed everything up, which is the reason for posting the code the way I just had to do.

Software Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT
Commented:
you could try something like this:

<form action="http://192.168.2.12" method="post" onsubmit="return doPost(this);">
<input type="hidden" name="Type" value="Results">
<table style="text-align:left; vertical-align:top;">
<tbody><tr>
  <td style="border:1px #000000 dotted; font-size:12px;">Search<br />
  <input type="submit" name="Submit" value="Search" tabindex="3">
<input name="Term" type="text" tabindex="1" width="200" value="KISS" onBlur="javascript:if (this.value == '') this.value = 'Search';" onFocus="javascript:if (this.value == 'Search') this.value='';">
<br />
<select class="FormUnits" name="Cat" tabindex="2">
<option value="3">Artist</option>
</select>
</td></tr>
</tbody></table>
<script type="text/javascript">
    function doPost(frm) {
        frm.action = "Search/" + frm.Term.value + "/" + frm.Cat.options[frm.Cat.selectedIndex].value;
        return true;
    }
</script>
</form>

Open in new window

Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:

As always, Ryan you are the best, my friend.
Have a-Rockin' week.

Wayne

Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT

Commented:
Cool, glad it worked = )
Wayne BarronAuthor, Web Developer
CERTIFIED EXPERT
Top Expert 2009

Author

Commented:

Worked great, just had to add in a replace in it, and works like a champ.
(See below) 

.replace(/ /g,"_")


Have to remove the spaces from between the words typed in.
Love it, works great!!!