-1

IIS URL書き換えを使用して、ユーザーを非WWWではなくWWWドメインに移動しようとしています。次の正規表現を使用してドメイン名を照合する記事に出くわしました。

^[^\.]+\.[^\.]+$

どの種類のドメインがこの正規表現と一致しているかわかりません。コードの完全な部分は次のとおりです。

<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>
4

1 に答える 1

3
^     # anchor the pattern to the beginning of the string
[^\.] # negated character class: matches any character except periods
+     # one or more of those characters
\.    # matches a literal period
[^\.] # negated character class: matches any character except periods
+     # one or more of those characters
$     # anchor the pattern to the end of the string

アンカーは、ドメインの周囲に許可されていないものがないことを確認するために重要です。

Tim Pietzkerが述べたように、ピリオドはキャラクタークラス内でエスケープする必要はありません。

あなたの質問に答えるために、最も基本的な方法:これは何に一致しますか?.最初の文字でも最後の文字でもない、を1つだけ含む文字列。

于 2012-12-07T14:53:26.577 に答える