2

最初に要求された URL にクエリ文字列が存在することに基づいて、web.config を使用してリダイレクトすることは可能ですか? 条件に何を入れたらいいのかわからない。私は web.config で書き換え/リダイレクト ルールを操作する初心者であり、構文、パラメーターなどについて詳しく知りたいと考えています。

私はこのようなことをしようとしています:

<rewrite>
<rules>

<rule name="Restricted Folder with Querystring" stopProcessing="true">
<match url="^test folder/(.*)" ignoreCase="false" />

    <conditions>
    <!--redirect to a certain page if a certain querystring is present -->
    </conditions>             
<action type="Redirect" redirectType="Permanent" url="/test folder/{R:1}" />
</rule>

<rule name="Restricted Folder without Querystring" stopProcessing="true">
<match url="^test folder/(.*)" ignoreCase="false" />              
    <conditions>
    <!--redirect to another page if querystring is not present -->
    </conditions>             
<action type="Redirect" redirectType="Permanent" url="https://www.whatever.com/page.asp?url={R:1}" />
</rule>

</rules>
</rewrite>
4

2 に答える 2

3

deeholzman、私はあなたの条件を信じています-「matchType」ではなく「パターン」を使用する入力例を追加します。元:

<add input="{QUERY_STRING}" pattern="^whateverpattern"  />

また

<add input="{QUERY_STRING}" pattern="^whateverpattern" negate="true" />
于 2013-07-18T18:32:10.543 に答える
2

URL Rewrite Module Configuration Referenceで答えを見つけました。リダイレクトを実行したいフォルダーの web.config の書き換えセクションでは、次のようになります。

<rules>
    <rule name="Restricted Folder Gimbal" stopProcessing="false">
      <match url="(.*)"  ignoreCase="true" />
      <conditions>
         <add input="{QUERY_STRING}" pattern="^whateverpattern"  />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://www.whatever.com/file.html" />
    </rule>     
  </rules>

クエリ文字列が存在しない場合は、「negate」パラメーターを条件に追加できます。

 <add input="{QUERY_STRING}" pattern="^whateverpattern"  negate="true" />

URL Rewrite Module Configuration Referenceは非常に便利なリファレンスですが、残念ながら見つけるのに予想以上に時間がかかりました。

于 2012-11-08T18:05:36.403 に答える