0

i am trying to rewrite any URL that match this pattern:

~/Ahmed
~/Name

to this:

~/User/Ahmed/Ahmed.aspx
~/User/Name/Name.aspx

and i can write them individually but what i am trying to do is detect any URL that look like "~/User/Ahmed/Ahmed" and auto rewrite them to this "Ahmed"

thanks

Wahtever
  • 3,597
  • 10
  • 44
  • 79

1 Answers1

0

Hopefully you're using the UrlRewritingNet library, not UrlRewriter? The former is suggested over the latter.

However, in either you can use a regex:

"~/User/([^/\\]+)/\1.aspx"  ->  "~/$1" //For ".aspx" in the URL
"~/([A-Za-z]+)" to "~/User/$1/$1.aspx" //For /Name in the URL.

Note the ([^/\]+) means any set of characters without slashes, and "\1" is a backreference to the previous capture, that ensures the name is an exact duplicate. Note that you should enable "ignore case" if you want to support "/User/ahmed/Ahmed.aspx" and not just "/User/Ahmed/Ahmed.aspx".

Lilith River
  • 16,204
  • 2
  • 44
  • 76