tweaking regex httpd.ini
2007-11-25 @ 12:47#
i was able to clean up my httpd.ini (i use ISAPI_Rewrite) file this morning. the result is that i now have a single RegEx filter for incoming requests instead of four - very nice!. this was done to help me sort out some representation support issues. it was a benefit that i was able to reduce the expressions. i was able to turn this:
# special call to the templates folder RewriteRule (.*)/xcs/templates/(.*) $1/xcs/templates/$2.xcs [L,I] # handle naked directory call RewriteRule (.*)/xcs/(.*)([.?/]) $1/xcs/$2$3.xcs [L,I] # has query args after the slash RewriteRule (.*)/xcs/(.*)(\?.*) $1/xcs/$2.xcs$3$4 [L,I] # missing backslash (assume trailing item is id) RewriteRule (.*)/xcs/([^.?]+[^.?/]) $1/xcs/$2$3.xcs$4 [L,I]
into this:
# updated rule (2007-11-24) RewriteRule (.*)/xcs/([^.?]*)(?:\.xcs)?(\?.*)? $1/xcs/$2.xcs$3 [L,I]
here's the expanded regex including comments for clarity:
@" ( # Match the regular expression below and capture its match into backreference number 1 . # Match any single character that is not a line break character * # Between zero and unlimited times, as many times as possible, giving back as needed (greedy) ) /xcs/ # Match the characters “/xcs/” literally ( # Match the regular expression below and capture its match into backreference number 2 [^.?] # Match a single character NOT present in the list “.?” * # Between zero and unlimited times, as many times as possible, giving back as needed (greedy) ) (?: # Match the regular expression below \. # Match the character “.” literally xcs # Match the characters “xcs” literally )? # Between zero and one times, as many times as possible, giving back as needed (greedy) ( # Match the regular expression below and capture its match into backreference number 3 \? # Match the character “?” literally . # Match any single character that is not a line break character * # Between zero and unlimited times, as many times as possible, giving back as needed (greedy) )? # Between zero and one times, as many times as possible, giving back as needed (greedy) "