1

I have the following regular expression used for pattern matching in a URL rewrite in IIS that was set up by my predecessor:

 ^$

I know very little regex, and the reading I've done this morning hasn't helped me in figuring out how this one works.

It is rewriting:

 http://dittest/

to:

 http://dittest:8080/dit

Why does the ^$ regex work in testing the URL http://dittest/ and rewriting to http://dittest:8080/dit if ^$ is supposed to match an empty string?

This question is not a duplicate, because it's not asking what the regex means – rather why it works in using it for an inbound rule URL rewrite in IIS when it doesn't work to validate http://dittest/.

I appreciate the help. Thank you!

vmil
  • 392
  • 6
  • 19
  • `^$` matches an empty string. – Wiktor Stribiżew Mar 06 '17 at 20:15
  • How does that work in this instance? I cannot get it to work for a similar rewrite for a different application. – vmil Mar 06 '17 at 20:19
  • Wiktor, the problem is that I'm trying to understand how it works. This is more of an IIS URL rewrite question than a regex question. When I test the pattern with http://dittest/ it does not validate, but the rewrite works regardless. – vmil Mar 06 '17 at 22:49
  • To supplement Wiktor's comment, `^` is a zero-length match of the beginning of a string and `$` is the inverse, matching the end of a string. With that said, IIS might be matching the path of the url (what is after `dittest/` which is nothing, hence the match). – Adam Mazzarella Mar 07 '17 at 02:27
  • I was thinking something similar, but then I tried to set up another app with identical configuration (IIS, DNS, ISAPI Filter, Inbound URL rewrite), but I could not get it to work, so I don't understand how it is working in this case. – vmil Mar 07 '17 at 21:42
  • @vmil Really? Because that works perfectly for me. Of course, you will need to add `127.0.0.1 dittest` to your `HOSTS` file and configure IIS to bind that host name. – Toothbrush Aug 30 '17 at 12:37
  • 1
    @vmil I would suggest you read https://weblogs.asp.net/owscott/url-parts-available-to-url-rewrite-rules. – Toothbrush Aug 30 '17 at 12:37

0 Answers0