IIS8でRedirect設定してみた

ウェブサーバを引っ越したので,元のサイトに「新しいサイトはこちら」みたいなのを書こうと思ったんだけど,もう直接Redirectするようにすればいいのか,と思ってやってみた.

昔 .htaccess に色々書く,というのをやったことがあったので試しにやってみたけど動かない.知らなかったんだけど,Windows のウェブサーバIISでは Web.config というのを使うそうだ.もう10年近くWindows Server だったのにこういうのしたことなかった.で,備忘録的にメモ.

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <location path="access.html">
    <system.webServer>
        <httpRedirect enabled="true" destination="https://tt-lab.jp/terada/contact.html" exactDestination="true" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>

  <location path="research">
    <system.webServer>
        <httpRedirect enabled="true" destination="https://tt-lab.jp/terada/research" exactDestination="true" httpResponseStatus="Permanent" />
    </system.webServer>
  </location>

  <system.webServer>
      <httpRedirect enabled="true" destination="https://tt-lab.jp/terada" exactDestination="true" httpResponseStatus="Permanent" />
  </system.webServer>
</configuration>

<location>タグの path に特定のファイル名書いて,そこに<httpRedirect>を書いておけば特定のパスを特定の行き先に転送.

<location>タグの path にディレクトリを書くと,そのディレクトリ以下のすべてのアクセスを特定の行き先に転送.

<location>タグをつけなければ上記特定パス以外全部を特定の行き先に転送.