I use url rewriting on my site and have implemented code:
r = new Regex(@"Default.aspx\?Buy=(?<1>[\w\-\+]*)(?:&|&)+PageIndex=(?<2>[\d]*)""", RegexOptions.IgnoreCase);
txt = r.Replace(txt, "$1_dp.html?page=$2\"");
In that case my links are:
http://www.mydomain.com/computers_dp.html?page=0 [1,2,3] depends on page number.
Is it simple way by RegEx to check if page = 0 then don’t add param ?page=0 and add it only if PageIndex is > 0.
Thanks!
Okay, I think this is the easiest way to solve this. Assuming the regex you have already implemented works, I would add another regex to simply replace
"?page=0"with"".There’s really no way to check the value of captured groups within a regex, aside from really painful conditional lookaheads, so just adding another regex to cut out the corner case is the simplest, and therefore best solution.