IISのリダイレクト変数を利用して、リダイレクトするディレクトリ内のページごとのリダイレクト先をまとめて設定する方法を紹介します。
リダイレクトURL内に以下の変数を含めることができます。
要求された URL において一致するサフィックスを渡します。一致するサフィックスとは、リダイレクト先の URL に置き換わった後もそのまま残る部分です。
上記の設定
と記述すると、当該ディレクトリへのすべてのファイルのアクセスは"http://www.ipentec.net/doc"への転送となります。ただしURLパラメーターは引き継がれません。
http://app.ipentec.com/catcher/ap/cont.html → http://www.ipentec.net/doc/cont.html
http://app.ipentec.com/catcher/ap/img/banner.jpg → http://www.ipentec.net/doc/img/banner.jpg
http://app.ipentec.com/catcher/ap/read.php?id=10 → http://www.ipentec.net/doc/read.php
元の URL のパラメータを渡します。
元の URL の疑問符 (?) とパラメータの両方を渡します。
要求された URL をサーバー名を除いて渡します。
要求された URL の中で、指定されたワイルドカードに一致する部分を渡します。
リダイレクトをしません。
"*"を用いることで任意の文字列と一致させることができます。
ワイルドカードを用いる場合はWeb.configファイルを直接編集して記述します。
拡張子がphpファイルにアクセスした際にドキュメントルートのdefault.htmlにリダイレクトする例です。
<configuration>
<system.webServer>
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
<add wildcard="*.php" destination="/default.html" />
</httpRedirect>
</system.webServer>
</configuration>
http://app.ipentec.com/app01/contents/pp.php → http://app.ipentec.com/default.html
http://app.ipentec.com/app01/contents/test.php → http://app.ipentec.com/default.html
http://app.ipentec.com/app01/contents/123.php → http://app.ipentec.com/default.html
下記の例では,拡張子がhtmlファイルにアクセスした際にhttp://www.ipentec.net/index.htmlにリダイレクトする例です。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
<add wildcard="*.html" destination="http://www.ipentec.net/index.html" />
</httpRedirect>
</system.webServer>
</configuration>
http://app.ipentec.com/app02/doc.html → http://www.ipentec.net/index.html
http://app.ipentec.com/app02/main.html → http://www.ipentec.net/index.html
http://app.ipentec.com/app02/index.html → http://www.ipentec.net/index.html