locked
"Url Rewriting - For Scott" RRS feed

  • Question

  • User-1069184416 posted
    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 ?

    regards
    Tuesday, April 12, 2005 4:57 PM

All replies

  • User-2077437193 posted
    It's been a while since I wrote that article (for those new to the thread see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/urlrewriting.asp), but IIRC the rules engine used regular expressions, no?  So couldn't you use a wildcard in the regular expression used to match the incoming URL?
    Tuesday, April 12, 2005 6:07 PM
  • User-1069184416 posted
    It's been a while since I wrote that article (for those new to the thread see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/urlrewriting.asp), but IIRC the rules engine used regular expressions, no?  So couldn't you use a wildcard in the regular expression used to match the incoming URL?

    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
    Wednesday, April 13, 2005 8:01 AM
  • User-2077437193 posted
    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?
    Wednesday, April 13, 2005 10:40 AM
  • User-1029435529 posted

    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.

    Tuesday, April 19, 2005 3:20 PM
  • User-1329334484 posted

    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...

     

     

    Monday, May 8, 2006 7:22 PM
  • User-1329334484 posted

    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:

    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/

     

    Wednesday, May 10, 2006 5:10 PM