GoDaddy がホストする Web サイトの書き換えルールをいくつか作成しているときに、奇妙な問題に遭遇しました。{HTTP_HOST}
または変数を使用して 1 つの書き換えルールを作成できます{SERVER_NAME}
が、2 番目のルールを追加するときに{HTTP_HOST}
/{SERVER_NAME}
が値を返さないように見えるので (推測)、コードが失敗します。
小さな間違いの後、問題の回避策を見つけました (これは最後に追加します)。次のことをしたいので、この質問をしています。
- この行動の理由を理解する
- これが他の誰かに起こっているかどうかを知る
- 私のアプローチが間違っているかどうか、またはそれが機能するために何かが欠けているかどうかを調べてください
この問題のため、テスト目的で web.config ファイル全体をクリアし、書き換えルールのみを保持することにしました。複数の変更を試みましたが、現時点ではすべてを思い出すことができないため、覚えている限り追加します。
問題
このコードは機能します
<system.webServer>
<rewrite>
<rules>
<rule name="Mask myFile.xml" stopProcessing="true" patternSyntax="Wildcard">
<!-- This rule always -->
<match url="*" />
<conditions>
<add input="{REQUEST_URI}" pattern="/myFile.xml" />
</conditions>
<action type="Rewrite" url="/SiteDependentFiles/{HTTP_HOST}/new_myFile.xml" appendQueryString="false"/>
</rule>
</rules>
</rewrite>
</system.webServer>
このコードはそうではありません (コード内のメモを参照してください)。
<system.webServer>
<rewrite>
<rules>
<rule name="Mask myFile.xml" stopProcessing="true" patternSyntax="Wildcard">
<!-- This rule works on and off. When it doesn't work, it returns a 404 (Not found) error -->
<match url="*" />
<conditions>
<add input="{REQUEST_URI}" pattern="/myFile.xml" />
</conditions>
<action type="Rewrite" url="/SiteDependentFiles/{HTTP_HOST}/new_myFile.xml" appendQueryString="false"/>
</rule>
<rule name="Mask thisThingy.txt" stopProcessing="true" patternSyntax="Wildcard">
<!-- This rule never works and it returns a 500 (Internal Server) error -->
<match url="*" />
<conditions>
<add input="{REQUEST_URI}" pattern="/thisThingy.txt" />
</conditions>
<action type="Rewrite" url="/SiteDependentFiles/{HTTP_HOST}/new_thisThingy.txt" appendQueryString="false"/>
</rule>
</rules>
</rewrite>
</system.webServer>
これが「詳細レポート」で得られるものです
404.0 エラー - 詳細
- モジュール: IIS Web コア
- 通知: MapRequestHandler
- ハンドラー: StaticFile
- エラー コード: 0x80070002
- 要求された URL: http://mySiteName.com:80/myFile.xml
- 物理パス: D:\Hosting\123123123\html\myFile.xml
- ログオン方法:匿名
- ログオン ユーザー:匿名
500.0 エラー - 詳細
- モジュール: ServerSideIncludeModule
- 通知: ExecuteRequestHandler
- ハンドラー: SSI-html
- エラー コード: 0x80070002
- 要求された URL: http://mySiteName.com:80/thisThingy.txt
- 物理パス: D:\Hosting\123123123\html\thisThingy.txt
- ログオン方法:匿名
- ログオン ユーザー:匿名
ここで、2 番目のルールのみ{HTTP_HOST}
の文字列を変更すると、両方のルールが機能し始めます。
<action type="Rewrite" url="/SiteDependentFiles/StaticFolderName/new_thisThingy.txt" appendQueryString="false"/>
ご注意ください:
の代わりに、の代わりに使用され、最初のルールの前に追加された別のpatternSyntax
オプションも使用してみましたが、何も変わりません。同じ動作。Redirect
Rewrite
stopProcessing="false"
{SERVER_NAME}
{HTTP_HOST}
<clear />
回避策
ルールのアクションの変数として使用できるように、常にルール条件を追加します{HTTP_HOST}
{SERVER_NAME}
<system.webServer>
<rewrite>
<rules>
<clear />
<!--
ALWAYS ADD <add input="{HTTP_HOST}" pattern="*" /> TO BE
ABLE TO USE {SERVER_NAME} MULTIPLE TIMES. (GODADDY ISSUE)
-->
<rule name="Mask myFile.xml" stopProcessing="true" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="*" />
<add input="{REQUEST_URI}" pattern="/myFile.xml" />
</conditions>
<action type="Rewrite" url="/SiteDependentFiles/{SERVER_NAME}/new_myFile.xml" appendQueryString="false"/>
</rule>
<rule name="Mask thisThingy.txt" stopProcessing="true" patternSyntax="Wildcard">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="*" />
<add input="{REQUEST_URI}" pattern="/thisThingy.txt" />
</conditions>
<action type="Rewrite" url="/SiteDependentFiles/{SERVER_NAME}/new_thisThingy.txt" appendQueryString="false"/>
</rule>
</rules>
</rewrite>
</system.webServer>
ご注意ください:
- と を使用
{HTTP_HOST}
しています{SERVER_NAME}
が、使用のみ{HTTP_HOST}
が機能します。現在、これをテストすることはできません。