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

URL Rerouting : How to find multiple sub-folders

Last post 12-02-2008, 7:19 AM by Sergei Z. 1 replies.
Sort Posts: Previous Next
  •  12-01-2008, 10:23 PM 49044

    URL Rerouting : How to find multiple sub-folders

    I have a situation where I am rerouting url as follows:

    /test-url/one/two/index.aspx to  /Categories.aspx?MID=one&CID=two

    I am using the following regex :

     ^/test-url/([^/]*)/([^/]*)/index.aspx which correctly matches when I have a structure like above. Now I may also have the structure as /test-url/one/index.aspx and would

    like to route it to /Categories.aspx?MID=one&CID=. However my regex (with obvious reasons) does not match this case. I  am not sure how to take care

    of multiple grouped matches?

    Please help!

     

    Thanks

    Swanand

    Filed under:
  •  12-02-2008, 7:19 AM 49057 in reply to 49044

    Re: URL Rerouting : How to find multiple sub-folders

    the strategy is to make the second folder optional:

    ^/test-url/([^/]*)/(([^/]*)/)?index.aspx

    u can also make the wrapping group non-capturing (?:  ) if your regex syntax allows for that:

     ^/test-url/([^/]*)/(?:([^/]*)/)?index.aspx

View as RSS news feed in XML