web-dev-qa-db-ja.com

Azure WebアプリでのURLの書き換え

Azure Webアプリに適用する単純なワイルドカードルーティングルールがあります。

<rule name="MyRule">
  <match url="*" />
  <action type="Rewrite" url="/index.html" />
</rule>

マシンにRDPできず、IISをいじることができない場合、ここにオプションはありますか?これはASP.Net Webサイトではなく、シンプルなSPAアプリケーションです。

9
Mister Epic

Wwwrootフォルダーにweb.configファイルを作成し、関連する構成エントリーをそこに配置する必要があります。

次に、web.configルールの例を示します。これは、ルールがどのように見えるかを理解するためのものです。

以下の例では、デフォルトの* .azurewebsites.netドメインをカスタムドメインにリダイレクトします( http://zainrizvi.io/blog/block-default-Azure-websites-domain/ を使用)。

<configuration>
  <system.webServer>  
    <rewrite>  
        <rules>  
          <rule name="Redirect rquests to default Azure websites domain" stopProcessing="true">
            <match url="(.*)" />  
            <conditions logicalGrouping="MatchAny">
              <add input="{HTTP_Host}" pattern="^yoursite\.azurewebsites\.net$" />
            </conditions>
            <action type="Redirect" url="http://www.yoursite.com/{R:0}" />  
          </rule>  
        </rules>  
    </rewrite>  
  </system.webServer>  
</configuration>
14
Zain Rizvi

このサーバーとサイトに解決されるすべてのURLをindex.htmlにリダイレクトするだけの場合は、次の書き換えセクションを使用できます。

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="SPA">
                    <match url=".*" />
                    <action type="Rewrite" url="index.html" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

これは、いくつかのマイナーな構文修正を除いて、あなたが持っているものと非常に似ています。パターンは「。*」であり、書き換えURLターゲットは単に「index.html」でなければなりません。これは、CSSやJSファイル、画像などの他のリソースの場合でも、サイトへのすべてのURLが書き換えられることを意味します。したがって、他のドメインからリソースをフェッチするほうがよいでしょう。

7

(リダイレクトではなく)実際の書き換えを行う場合は、次の内容でサイトフォルダーに配置されたapplicationHost.xdtファイルでARRを有効にすることを忘れないでください。

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.Microsoft.com/XML-Document-Transform">
  <system.webServer>
    <proxy xdt:Transform="InsertIfMissing" enabled="true" preserveHostHeader="false" reverseRewriteHostInResponseHeaders="false" />
    <rewrite>
      <allowedServerVariables>
        <add name="HTTP_ACCEPT_ENCODING" xdt:Transform="Insert" />
        <add name="HTTP_X_ORIGINAL_Host" xdt:Transform="Insert" />
      </allowedServerVariables>
    </rewrite>
  </system.webServer>
</configuration> 
4
Lech Migdal