I am trying to use IIS URL rewrite to take a user to a WWW domain instead of a non-WWW. I came across an article which uses the following regex to match domain names:
^[^\.]+\.[^\.]+$
I can’t figure out what sort of domain is being matched with this regex. Here is the complete piece of code:
<rule name="www redirect" enabled="true" stopProcessing="true">
<match url="." />
<conditions>
<add input="{HTTP_HOST}" **pattern="^[^\.]+\.[^\.]+$"** />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" />
</rule>
<rule name="www redirect https" enabled="true" stopProcessing="true">
<match url="." />
<conditions>
<add input="{HTTP_HOST}" **pattern="^[^\.]+\.[^\.]+$"** />
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" />
</rule>
The anchors are important to make sure that there is nothing around the domain that is not allowed.
As Tim Pietzker mentioned, the periods do not need to be escaped inside the character class.
To answer your question, the most basic way: what does this match? Any string that contains exactly one
., which is neither the first nor the last character.