Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Help with URL Rewriting

Last post 03-31-2008, 11:45 PM by jeff.hillman. 1 replies.
Sort Posts: Previous Next
  •  03-31-2008, 9:21 PM 40882

    Help with URL Rewriting

    I'm using an ISAPI filter for rewriting URL's on IIS (IIRF). The filter process uses C regular expression syntax and a config file to list all the URL rewriting rules.

    The config file is simple and works such that each line is a rule, like so:
    RewriteRule  <regex match expr>  <regex replace expr>  [flags]

    I have many rules working properly now and I need to extend this one explained below just a bit. It's simply a regex matching rule so I thought you all could help.
    I have this rule working properly.

    the rule below rewrites this url: /artists/999/my-band-name  into this url: /artists/artist.aspx?artistid=999&a=my-band-name
    RewriteRule ^/artists/(\d+){1}/((?>([^?/\n]|/[^.?/\n])+)(?<!\.aspx))(/?)$    /artists/artist.aspx?artistid=$1&a=$2

    Now I need to extend this so that it can take another "folder" at the end, which will denote the page to call. Like so:

    /artists/999/my-band-name/shows  into:  /artists/shows.aspx?artistid=999&a=my-band-name
    and
    /artists/999/my-band-name/articleinto:  /artists/articles.aspx?artistid=999&a=my-band-name

    I've tried this rule and many variations but it's not working.
    RewriteRule ^/artists/(\d+){1}/((?>([^?/\n]|/[^.?/\n])+)(?<!\.aspx))/((shows|goods|fans|articles)+)(/?)$   /artists/$3.aspx?id=$1&a=$2

    What would be great is to only capture certain page names in this format (shows|fans|articles) ... I've messed with this a LOT to get it working and I cannot. I think my negative lookbehind for the .aspx might be screwing it up? 

    Any help or pointers is greatly appreciated! 

  •  03-31-2008, 11:45 PM 40886 in reply to 40882

    Re: Help with URL Rewriting

    mason,

    The problem with your new rule is that the first part of your expression, "^/artists/(\d+){1}/((?>([^?/\n]|/[^.?/\n])+)(?<!\.aspx))" will match all of the URL "/artists/999/my-band-name/shows", but your expression continues, requiring "/((shows|goods|fans|articles)+)(/?)$" to match as well, which it never will.  I don't see the point of the second alternative in '([^?/\n]|/[^.?/\n])'; can a band name really contain a slash?  Without this alternative, the expression matches fine, and I imagine the rule would look like this:

    ^/artists/(\d+)/((?>([^?/\n])+)(?<!\.aspx))/?(shows|goods|fans|articles)+/?$  /artists/$4.aspx?id=$1&a=$2

    The '{1}' after '(\d+)' is unnecessary, so I removed it as well.  The changes I made here apply to the first rule as well.  I have zero experience with URL rewriting, so please forgive my ignorance if I have misunderstood something here.

     
    Jeff
     


View as RSS news feed in XML