473,395 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Url Rewriting Trouble

I'm using the free UrlRewriter.Net HttpModule to perform url rewrites on my website.
Well, sort of. The thing is, I can't get the rewrites to work.

After creating a configSection and adding the component to the httpModule section of my
web.config file, I began writing rules. Here's a sample of what I have:

<rewriter>
<rewrite url="~/Products/(.+)" to="~/Products/default.aspx?category=$1"/>
<rewrite url="~/Products/(.+)/(\d+)"
to="~/Products/default.aspx?category=$1&amp;page=$2"/>
</rewriter>
While testing the first rule, everything works perfectly. The second rule, unfortunately,
screws up. Instead of having two querystring parameters, ASP.NET only sees one. For
example, suppose a customer had "~/Products/CDs/3" in their address bar. ASP.NET doesn't
see it as "~/Products/default.aspx?category=CDs&page=3" but rather views it as
"~/Products/default.aspx?category=CDs/3"

Why isn't this working? Is my use of regular expressions wrong (I'm not good at them)?
Please help. :(

Roshawn
Jun 27 '08 #1
4 1129
"Roshawn" <ra*********@yahoo.comwrote in message
news:OY****************@TK2MSFTNGP05.phx.gbl...
I'm using the free UrlRewriter.Net HttpModule to perform url rewrites on
my website.
Well, sort of. The thing is, I can't get the rewrites to work.

After creating a configSection and adding the component to the httpModule
section of my
web.config file, I began writing rules. Here's a sample of what I have:

<rewriter>
<rewrite url="~/Products/(.+)"
to="~/Products/default.aspx?category=$1"/>
<rewrite url="~/Products/(.+)/(\d+)"
to="~/Products/default.aspx?category=$1&amp;page=$2"/>
</rewriter>
While testing the first rule, everything works perfectly. The second
rule, unfortunately,
screws up. Instead of having two querystring parameters, ASP.NET only
sees one. For
example, suppose a customer had "~/Products/CDs/3" in their address bar.
ASP.NET doesn't
see it as "~/Products/default.aspx?category=CDs&page=3" but rather views
it as
"~/Products/default.aspx?category=CDs/3"

Why isn't this working? Is my use of regular expressions wrong (I'm not
good at them)?
Please help. :(
The (.+) is greedy (yes this the technical term for it) and gobbles up the
/ and everything after it

You can use (.+?) to stop it being greedy or use ([^/]+) which keeps
matching characters until it finds a / .


--
Anthony Jones - MVP ASP/ASP.NET
Jun 27 '08 #2
Thanks for the reply, Anthony.

Trying your first suggestion (i.e. (.+?)) produced the same result as the first. Your
second suggestion (i.e. ([^/]+)) allows only the category parameter to be read; the page
parameter gets ignored completely.

I tried using the second suggestion with an underscore character. I was able to get the
page parameter, but the category parameter changed to
"~/Products/default.aspx?category=$1" IOW, the category parameter contained the
directory, page name and all.

I appreciate your trying to help me. You've given me more than I had before. Hopefully I
can get things working properly.

Thanks again,
Roshawn

Anthony Jones wrote:
"Roshawn" <ra*********@yahoo.comwrote in message
news:OY****************@TK2MSFTNGP05.phx.gbl...
>I'm using the free UrlRewriter.Net HttpModule to perform url rewrites on
my website.
>Well, sort of. The thing is, I can't get the rewrites to work.

After creating a configSection and adding the component to the httpModule
section of my
>web.config file, I began writing rules. Here's a sample of what I have:

<rewriter>
<rewrite url="~/Products/(.+)"
to="~/Products/default.aspx?category=$1"/>
> <rewrite url="~/Products/(.+)/(\d+)"
to="~/Products/default.aspx?category=$1&amp;page=$2"/>
</rewriter>
While testing the first rule, everything works perfectly. The second
rule, unfortunately,
>screws up. Instead of having two querystring parameters, ASP.NET only
sees one. For
>example, suppose a customer had "~/Products/CDs/3" in their address bar.
ASP.NET doesn't
>see it as "~/Products/default.aspx?category=CDs&page=3" but rather views
it as
>"~/Products/default.aspx?category=CDs/3"

Why isn't this working? Is my use of regular expressions wrong (I'm not
good at them)?
>Please help. :(

The (.+) is greedy (yes this the technical term for it) and gobbles up the
/ and everything after it

You can use (.+?) to stop it being greedy or use ([^/]+) which keeps
matching characters until it finds a / .

Jun 27 '08 #3
"Roshawn" <ra*********@yahoo.comwrote in message
news:u7**************@TK2MSFTNGP06.phx.gbl...
Thanks for the reply, Anthony.

Trying your first suggestion (i.e. (.+?)) produced the same result as the
first. Your
second suggestion (i.e. ([^/]+)) allows only the category parameter to be
read; the page
parameter gets ignored completely.

I tried using the second suggestion with an underscore character. I was
able to get the
page parameter, but the category parameter changed to
"~/Products/default.aspx?category=$1" IOW, the category parameter
contained the
directory, page name and all.

I appreciate your trying to help me. You've given me more than I had
before. Hopefully I
can get things working properly.
This must be something to do with how the product works. I've tested my
suggestions as regular expressions and they clearly work. I wonder whether
the string parsing requirements of the product include the need to escape
the \ character. Try this:-

"~/Products/([^/]+)/(\\d+)"

Note the \\ infront of the d.

In fact the greedy version works with that mod but I would use the above.

--
Anthony Jones - MVP ASP/ASP.NET
Jun 27 '08 #4
You can try IIRF - another rewriting filter. It also uses regular
expressions.
www.codeplex.com/IIRF.
(free)
"Anthony Jones" wrote:
"Roshawn" <ra*********@yahoo.comwrote in message
news:u7**************@TK2MSFTNGP06.phx.gbl...
Thanks for the reply, Anthony.

Trying your first suggestion (i.e. (.+?)) produced the same result as the
first. Your
second suggestion (i.e. ([^/]+)) allows only the category parameter to be
read; the page
parameter gets ignored completely.

I tried using the second suggestion with an underscore character. I was
able to get the
page parameter, but the category parameter changed to
"~/Products/default.aspx?category=$1" IOW, the category parameter
contained the
directory, page name and all.

I appreciate your trying to help me. You've given me more than I had
before. Hopefully I
can get things working properly.

This must be something to do with how the product works. I've tested my
suggestions as regular expressions and they clearly work. I wonder whether
the string parsing requirements of the product include the need to escape
the \ character. Try this:-

"~/Products/([^/]+)/(\\d+)"

Note the \\ infront of the d.

In fact the greedy version works with that mod but I would use the above.

--
Anthony Jones - MVP ASP/ASP.NET
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jamie Jackson | last post by:
I'm rewriting all links' onclick events, but I'm having a problem. The onclick event that I'm inserting works correctly in Opera, but not in FF or IE. I'm retroactively adding the statement...
2
by: Thedotnetteer | last post by:
hi. I wrote a very simple httpmodule to transform calls as www.mysite.com/users/john to www.mysite.com/userspage.aspx?id=john the problem is that my module is called only when the called page...
0
by: Lee | last post by:
Hi all ;) Preamble -------- I'm using URL rewriting to enforce a frames policy (yeah, I know frames are 'bad' :) - i.e. if a request comes in for a page which should be nested within a...
9
by: Alan Silver | last post by:
Hello, I would like to be able to use an URL like ... http://www.whatever.com/order/123 and have it translated into ... http://www.whatever.com/orders.aspx?orderid=123
3
by: Smokey Grindel | last post by:
I am using ASP.NET 2.0 and know about the static list in the web.config for URL rewriting, but my list is dynamic and I am running into some problems... 1) How do you get URL rewriting to work in...
3
by: Greg Collins [Microsoft MVP] | last post by:
I have done a bit of research of Url Rewriting, but as yet have been unsuccessful at getting it to work well, and there are issues around what file types are supported and how much code you want to...
8
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I'm having trouble with URL rewriting using HttpApplication.Context.RewritePath in a web application I've created. Everything works, but the links (css, images) in the pages break when...
2
by: Moistly | last post by:
Has ever tried to do URL rewriting in ASP.NET 2.0 ie I have no trouble on my own machine but it just doesn't seem to work dev server Basically I am trying to map something like ...
15
by: Chris Jones | last post by:
I wrote a trivial backup script that does the following: If tonight is the first day of the month: save last month's archive do a full backup of the system else: save last night's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.