Hello:
I have read Scott's article on URL Rewriting and in fact it was the basis on which I created my own rewriter.
I would like to know if it is possible to have an article on including wildcard url conversion in that url rewriter, which is having more explanation on how to create the rule's engine to process more complex url rewriting.
Is that possible ? Or is it even possible to redirect me to place where I can find such things ?
IIRC the rules engine in the article I wrote used regular expressions to match the incoming requested URL. So I don't see why you couldn't use that to implement a wildcard. Have you tried using the code from the article? If so, what in particular is gumming
you up?
Happy Programming!
-- Scott Mitchell
-- mitchell@fuzzylogicinc.net
-- http://scottonwriting.net/sowBlog/
-- http://scottonwriting.net/ScottMitchell
The code from Scott's article can be updated to use wildcards. My equivalent of Scott's "LookFor" rule allows for wildcards (*) in place of both filenames and extensions:
/articles/url-rewriting
/articles/url-rewriting.* (to match .pdf downloadable version of the above)
/articles/* (to match a request for any article)
/articles/*.* (to match darn near everything)
What I do is first order the rules from the most specific (no wildcards) to the least specific (two wildcards). Then I loop through the collection of rules. Because of the ordering, a specific match will be found before a non-specific match, which is what
I want.
A filename wildcard is replaced with the following regular expression pattern:
(([a-zA-z0-9_\-])*?)
An extension wildcard is replaced with another regular expression pattern. I won't provide it, as it is linked to a certain URL style that I am using.
Having replaced the friendly wildcards (*) with regular expression patterns, the remainder of Scott's code would work without change.
I would like to rewrite any Link with query string on my site. I was thinking about this rule:
1) Original URL - ~/Default.aspx?CategoryId=10
2) Rewritten URL ~/categoryID/10/Default.aspx
The above would be only executed as the last rule (if no other rules found), to make the site Search Engine friendly. So If there is Rule let's s say for Category=10, then that rule would be used instead...
The number of possible parameters would be unlimited. Any link could be converted to this form...
Do you think this can be done easly using your URL rewriter? Can I implement this using Regex and place the last rule (not sure about regex here and SendTo). Maybe I could just modify the engine and put all to the array and than parse? This would be the
last step after all rules failed...
The article is great but it does not address the issue with relative paths. If the rewritten URL has a different path than the originnal the relative links on the page will not work Is there a way to resolve this problem?
Contributor
4057 Points
8649 Posts
MVP
"Url Rewriting - For Scott"
Apr 12, 2005 04:57 PM|haidar_bilal|LINK
I have read Scott's article on URL Rewriting and in fact it was the basis on which I created my own rewriter.
I would like to know if it is possible to have an article on including wildcard url conversion in that url rewriter, which is having more explanation on how to create the rule's engine to process more complex url rewriting.
Is that possible ? Or is it even possible to redirect me to place where I can find such things ?
regards
Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB
Participant
1346 Points
691 Posts
ASPInsiders
Re: "Url Rewriting - For Scott"
Apr 12, 2005 06:07 PM|Scott Mitchell|LINK
-- Scott Mitchell
-- mitchell@fuzzylogicinc.net
-- http://scottonwriting.net/sowBlog/
-- http://scottonwriting.net/ScottMitchell
Contributor
4057 Points
8649 Posts
MVP
Re: "Url Rewriting - For Scott"
Apr 13, 2005 08:01 AM|haidar_bilal|LINK
You mean, I use the same rule's engine you had in the article but add my own repalcements ? Will the same engine work ?
regards
Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB
Participant
1346 Points
691 Posts
ASPInsiders
Re: "Url Rewriting - For Scott"
Apr 13, 2005 10:40 AM|Scott Mitchell|LINK
-- Scott Mitchell
-- mitchell@fuzzylogicinc.net
-- http://scottonwriting.net/sowBlog/
-- http://scottonwriting.net/ScottMitchell
Participant
1001 Points
7915 Posts
Re: "Url Rewriting - For Scott"
Apr 19, 2005 03:20 PM|SomeNewKid|LINK
The code from Scott's article can be updated to use wildcards. My equivalent of Scott's "LookFor" rule allows for wildcards (*) in place of both filenames and extensions:
/articles/url-rewriting
/articles/url-rewriting.* (to match .pdf downloadable version of the above)
/articles/* (to match a request for any article)
/articles/*.* (to match darn near everything)
What I do is first order the rules from the most specific (no wildcards) to the least specific (two wildcards). Then I loop through the collection of rules. Because of the ordering, a specific match will be found before a non-specific match, which is what I want.
A filename wildcard is replaced with the following regular expression pattern:
(([a-zA-z0-9_\-])*?)
An extension wildcard is replaced with another regular expression pattern. I won't provide it, as it is linked to a certain URL style that I am using.
Having replaced the friendly wildcards (*) with regular expression patterns, the remainder of Scott's code would work without change.
Try it and see for yourself.
Member
19 Points
1676 Posts
Re: "Url Rewriting - For Scott"
May 08, 2006 07:22 PM|rfurdzik|LINK
I love the article! Good job!
I would like to rewrite any Link with query string on my site. I was thinking about this rule:
1) Original URL - ~/Default.aspx?CategoryId=10
2) Rewritten URL ~/categoryID/10/Default.aspx
The above would be only executed as the last rule (if no other rules found), to make the site Search Engine friendly. So If there is Rule let's s say for Category=10, then that rule would be used instead...
The number of possible parameters would be unlimited. Any link could be converted to this form...
Do you think this can be done easly using your URL rewriter? Can I implement this using Regex and place the last rule (not sure about regex here and SendTo). Maybe I could just modify the engine and put all to the array and than parse? This would be the last step after all rules failed...
Wonder what your thoughts are...
Member
19 Points
1676 Posts
Re: "Url Rewriting - For Scott"
May 10, 2006 05:10 PM|rfurdzik|LINK
The article is great but it does not address the issue with relative paths. If the rewritten URL has a different path than the originnal the relative links on the page will not work Is there a way to resolve this problem?
Original link:
http://localhost/csk11/cid/10/default.aspx
Rewritten link:
http://localhost/csk11/catalog.aspx?cid=10&m=13
This is the link created on CSK catalog page:
<ItemTemplate> <a href="catalog.aspx?cid=<%#Eval("categoryid") %>" class="subcategory"><%#Eval("categoryName") %></a><br/> </ItemTemplate>It will become:
<div class=ForumPostContentText id=_ctl0__ctl1_bcr__ctl0___PostRepeater__ctl3_PostViewWrapper>http://localhost/csk11/cid/10/catalog.aspx?cid=10&m=13
yet it should really be:
http://localhost/csk11/catalog.aspx?cid=10&m=13
I have realized that the item template SHOULD USE the rewritten path, which is http://localhost/csk11/ instead of using the original path http://localhost/csk11/cid/10/