Share via


HTTP 리디렉션 <httpRedirect>

요소는 <httpRedirect> 클라이언트 요청을 새 위치로 리디렉션하는 IIS(인터넷 정보 서비스) 7에 대한 설정을 구성합니다.

클라이언트를 새 위치로 리디렉션하려는 몇 가지 이유가 있습니다. 예를 들어 회사에서 새 웹 사이트로 마이그레이션하는 경우 이전 웹 사이트의 모든 요청을 새 웹 사이트로 리디렉션할 수 있습니다. 마찬가지로 웹 서버에 새 애플리케이션을 배포한 경우 이전 애플리케이션의 URL 네임스페이스에 대한 모든 요청(예: http://www.contoso.com/app_v1.0/)을 새 애플리케이션 위치(예 http://www.contoso.com/app_v2.0/: )로 리디렉션할 수 있습니다.

가장 간단한 구성에서는 클라이언트를 새 위치로 리디렉션하기 위해 요소의 <httpRedirect>사용대상 특성만 설정하면 됩니다. 그러나 exactDestinationhttpResponseStatus 특성과 같은 추가 요소를 사용하면 IIS 7이 입력한 대로 대상 URL을 정확하게 반환할지 여부와 웹 클라이언트로 반환할 HTTP 응답 코드를 각각 지정하여 리디렉션의 최종 사용자 환경을 구성할 수 있습니다.

호환성

버전 참고
IIS 10.0 추가 HTTP 응답 상태 IIS 10.0의 요소에 추가 <httpRedirect> 되었습니다.
IIS 8.5 <httpRedirect> 요소가 IIS 8.5에서 수정되지 않았습니다.
IIS 8.0 <httpRedirect> 요소가 IIS 8.0에서 수정되지 않았습니다.
IIS 7.5 <httpRedirect> 요소가 IIS 7.5에서 수정되지 않았습니다.
IIS 7.0 요소는 <httpRedirect> IIS 7.0에서 도입되었습니다.
IIS 6.0 요소는 <httpRedirect> IIS 6.0 HttpRedirect 메타베이스 속성을 대체합니다.

설치 프로그램

HTTP 리디렉션은 IIS 7 이상의 기본 설치에서 사용할 수 없습니다. 설치하려면 다음 단계를 사용합니다.

Windows Server 2012 또는 Windows Server 2012 R2

  1. 작업 표시줄에서 서버 관리자를 클릭합니다.
  2. 서버 관리자관리 메뉴를 클릭한 다음 역할 및 기능 추가를 클릭합니다.
  3. 역할 및 기능 추가 마법사에서 다음을 클릭합니다. 설치 유형을 선택하고 다음을 클릭합니다. 대상 서버를 선택하고 다음을 클릭합니다.
  4. 서버 역할 페이지에서 웹 서버(IIS)를 확장하고 웹 서버를 확장하고 일반적인 HTTP 기능을 확장한 다음 HTTP 리디렉션을 선택합니다. 다음을 클릭합니다.
    서버 역할 페이지의 스크린샷 H T T P 리디렉션이 선택되고 강조 표시됩니다. .
  5. 기능 선택 페이지에서 다음을 클릭합니다.
  6. 설치 선택 확인 페이지에서 설치를 클릭합니다.
  7. Results(결과) 페이지에서 Close(닫기)를 클릭합니다.

Windows 8 또는 Windows 8.1

  1. 시작 화면에서 포인터를 왼쪽 아래 모서리로 이동하고 시작 단추를 마우스 오른쪽 단추로 클릭한 다음 제어판 클릭합니다.
  2. 제어판프로그램 및 기능을 클릭한 다음 Windows 기능 켜기 또는 끄기를 클릭합니다.
  3. 인터넷 정보 서비스를 확장하고, World Wide Web Services를 확장하고, 일반적인 HTTP 기능을 확장한 다음, HTTP 리디렉션을 선택합니다.
    인터넷 정보 서비스 탐색 트리의 스크린샷 World Wide Web Services 옵션이 확장되었습니다. 일반적인 H T T P 기능이 확장되고 H T T P 리디렉션이 선택됩니다.
  4. 확인을 클릭합니다.
  5. 닫기를 클릭합니다.

Windows Server 2008 또는 Windows Server 2008 R2

  1. 작업 표시줄에서 시작을 클릭하고 관리 도구를 가리킨 다음 서버 관리자 클릭합니다.
  2. 서버 관리자 계층 구조 창에서 역할을 확장한 다음 웹 서버(IIS)를 클릭합니다.
  3. 웹 서버(IIS) 창에서 Role Services 섹션으로 스크롤한 다음 역할 서비스 추가를 클릭합니다.
  4. 역할 서비스 추가 마법사역할 서비스 선택 페이지에서 공통 Http 기능을 확장하고 HTTP 리디렉션을 선택한 다음 다음을 클릭합니다.
    Role Services 섹션의 스크린샷 H T T P 리디렉션이 선택되고 강조 표시됩니다.
  5. 설치 선택 확인 페이지에서 설치를 클릭합니다.
  6. Results(결과) 페이지에서 Close(닫기)를 클릭합니다.

Windows Vista 또는 Windows 7

  1. 작업 표시줄에서 시작을 클릭한 다음 제어판 클릭합니다.
  2. 제어판프로그램 및 기능을 클릭한 다음 Windows 기능 켜기 또는 끄기를 클릭합니다.
  3. 인터넷 정보 서비스, World Wide Web Services, 일반 Http 기능을 차례로 확장합니다.
  4. HTTP 리디렉션을 선택한 다음 확인을 클릭합니다.
    프로그램 및 기능 탐색 트리의 스크린샷 H T T P 리디렉션이 선택되고 강조 표시됩니다.

방법

IIS 7에 대한 와일드카드 HTTP 리디렉션을 추가하기 위한 사용자 인터페이스가 없습니다. 요소를 프로그래밍 방식으로 요소에 <httpRedirect> 추가하는 <add> 방법의 예는 이 문서의 코드 샘플 섹션을 참조하세요.

웹 사이트 또는 애플리케이션에 HTTP 리디렉션 규칙을 추가하는 방법

  1. IIS(인터넷 정보 서비스) 관리자를 엽니다.

    • Windows Server 2012 사용하거나 R2를 Windows Server 2012 경우:

      • 작업 표시줄에서 서버 관리자 클릭하고 도구를 클릭한 다음 IIS(인터넷 정보 서비스) 관리자를 클릭합니다.
    • Windows 8 사용하거나 Windows 8.1 경우:

      • Windows 키를 누른 채로 문자 X를 누른 다음 제어판 클릭합니다.
      • 관리 도구를 클릭한 다음 IIS(인터넷 정보 서비스) 관리자를 두 번 클릭합니다.
    • Windows Server 2008 또는 Windows Server 2008 R2를 사용하는 경우:

      • 작업 표시줄에서 시작을 클릭하고 관리 도구를 가리킨 다음 IIS(인터넷 정보 서비스) 관리자를 클릭합니다.
    • Windows Vista 또는 Windows 7을 사용하는 경우:

      • 작업 표시줄에서 시작을 클릭한 다음 제어판 클릭합니다.
      • 관리 도구를 두 번 클릭한 다음 IIS(인터넷 정보 서비스) 관리자를 두 번 클릭합니다.
  2. 연결 창에서 서버 이름을 확장하고 사이트를 확장한 다음 사용자 지정 오류 페이지를 구성하려는 웹 사이트 또는 애플리케이션으로 이동합니다.

  3. 창에서 HTTP 리디렉션을 두 번 클릭합니다.
    홈 창의 스크린샷 H T T P 리디렉션 아이콘이 강조 표시되고 선택됩니다.

  4. HTTP 리디렉션 창에서 상자를 검사 요청을 리디렉션하고 대상 URL을 입력합니다.
    H T TP 리디렉션 창의 스크린샷 이 대상으로 요청을 리디렉션 옆의 상자가 선택되어 있습니다.

  5. 필요에 따라 다음 옵션 중 원하는 옵션을 지정할 수 있습니다.

    • 리디렉션 대상을 입력한 정확한 대상으로 구성합니다.

    • 하위 폴더가 아닌 대상 URL의 루트 폴더로 제한되도록 리디렉션 대상을 구성합니다.

    • 다음 옵션 중 하나일 수 있는 HTTP 상태 코드를 구성합니다.

      • 301 영구
      • 302 있음
      • 307 임시
      • 308 영구 리디렉션

      참고

      IIS 7은 각각 위의 각 옵션에 대해 다음과 같은 실제 HTTP 응답 상태를 반환합니다.

      • HTTP/1.1 301 영구적으로 이동
      • HTTP/1.1 302 리디렉션
      • HTTP/1.1 307 리디렉션
      • HTTP 1.1 308 영구적으로 리디렉션됨
  6. 위의 모든 변경 내용을 완료했으면 작업 창에서 적용을 클릭합니다.

구성

특성

attribute Description
childOnly 선택적 부울 특성입니다.

리디렉션할 요청을 포함하는 파일 이름의 시작 부분에 대상 값을 추가할지 여부를 지정합니다. 예를 들어 childOnly 가 true로 설정되고 대상 값이 로 구성된 http://marketing.contoso.com/경우 에 대한 http://contoso.com/default.htm 요청이 로 http://marketing.contoso.com/default.htm리디렉션됩니다.

기본값은 false입니다.
destination 선택적 문자열 특성입니다.

클라이언트를 리디렉션할 URL 또는 가상 경로를 지정합니다.
enabled 선택적 부울 특성입니다.

리디렉션을 사용할지(true) 또는 사용 안 함(false)을 지정합니다.

기본값은 false입니다.
exactDestination 선택적 부울 특성입니다.

대상 값이 상대 위치가 아닌 절대 대상 위치로 간주되도록 지정합니다.

기본값은 false입니다.
httpResponseStatus 선택적 열거형 특성입니다.

리디렉션 유형을 지정합니다.

httpResponseStatus 특성은 다음과 같은 가능한 값 중 하나일 수 있습니다. 기본값은 Found입니다.
Description
Found 대상 특성에 지정된 위치에 새 요청을 실행하도록 클라이언트에 지시하는 302 상태 코드를 반환합니다.

숫자 값은 입니다 302.
Permanent 요청된 리소스의 위치가 영구적으로 변경되었음을 클라이언트에 알리는 301 상태 코드를 반환합니다.

숫자 값은 입니다 301.
Temporary 브라우저에서 HTTP POST 요청을 발급할 때 클라이언트가 데이터를 잃지 않도록 하는 307 상태 코드를 반환합니다.

숫자 값은 입니다 307.
PermRedirect 요청된 리소스의 위치가 영구적으로 변경되었음을 클라이언트에 알리는 308 상태 코드를 반환합니다.

숫자 값은 입니다 308.

자식 요소

요소 Description
add 선택적 요소입니다.

리디렉션 규칙 컬렉션에 와일드카드 리디렉션 규칙을 추가합니다.
clear 선택적 요소입니다.

리디렉션 규칙 컬렉션에서 와일드카드 리디렉션 규칙에 대한 모든 참조를 제거합니다.
remove 선택적 요소입니다.

리디렉션 규칙 컬렉션에서 와일드카드 리디렉션 규칙에 대한 참조를 제거합니다.

구성 샘플

다음 기본 <httpRedirect> 요소는 HTTP 리디렉션 역할 서비스가 설치될 때 IIS 7의 루트 ApplicationHost.config 파일에 구성됩니다. 이 구성 섹션은 요소를 사용하지 않는 한 기본 구성 설정을 상속합니다 <clear> .

<system.webServer>
   <httpRedirect enabled="false" />
</system.webServer>

다음 구성 샘플은 리디렉션을 사용하도록 설정하고 클라이언트가 리디렉션되는 대상 URL을 구성합니다.

<system.webServer>
   <httpRedirect enabled="true" destination="http://www.contoso.com/" />
</system.webServer>

다음 구성 샘플에서는 PHP 파일에 대한 모든 요청을 웹 사이트의 홈페이지로 리디렉션하는 와일드카드 리디렉션 항목을 추가합니다.

참고

이 예제는 웹 사이트에서 모든 ASP 기반 애플리케이션을 제거하고 이전 애플리케이션에 대한 클라이언트 요청을 HTTP 404 찾을 수 없음 응답을 수신하지 않고 웹 사이트의 루트로 리디렉션하려는 경우에 유용합니다.

<configuration>
   <system.webServer>
      <httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
         <add wildcard="*.php" destination="/default.htm" />
      </httpRedirect>
   </system.webServer>
</configuration>

샘플 코드

다음 코드 샘플은 HTTP 302 상태 코드를 사용하여 모든 요청을 리디렉션하도록 http://www.contoso.com 기본 웹 사이트를 구성합니다.

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/httpRedirect /enabled:"True"
appcmd.exe set config "Default Web Site" -section:system.webServer/httpRedirect /destination:"http://www.contoso.com"
appcmd.exe set config "Default Web Site" -section:system.webServer/httpRedirect /exactDestination:"False"
appcmd.exe set config "Default Web Site" -section:system.webServer/httpRedirect /httpResponseStatus:"Found"

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using (ServerManager serverManager = new ServerManager())
      {
         Configuration config = serverManager.GetWebConfiguration("Default Web Site");

         ConfigurationSection httpRedirectSection = config.GetSection("system.webServer/httpRedirect");
         httpRedirectSection["enabled"] = true;
         httpRedirectSection["destination"] = @"http://www.contoso.com";
         httpRedirectSection["exactDestination"] = false;
         httpRedirectSection["httpResponseStatus"] = @"Found";

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetWebConfiguration("Default Web Site")

      Dim httpRedirectSection As ConfigurationSection = config.GetSection("system.webServer/httpRedirect")
      httpRedirectSection("enabled") = True
      httpRedirectSection("destination") = "http://www.contoso.com"
      httpRedirectSection("exactDestination") = False
      httpRedirectSection("httpResponseStatus") = "Found"

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site";

var httpRedirectSection = adminManager.GetAdminSection("system.webServer/httpRedirect", "MACHINE/WEBROOT/APPHOST/Default Web Site");
httpRedirectSection.Properties.Item("enabled").Value = true;
httpRedirectSection.Properties.Item("destination").Value = "http://www.contoso.com";
httpRedirectSection.Properties.Item("exactDestination").Value = false;
httpRedirectSection.Properties.Item("httpResponseStatus").Value = "Found";

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site"

Set httpRedirectSection = adminManager.GetAdminSection("system.webServer/httpRedirect", "MACHINE/WEBROOT/APPHOST/Default Web Site")
httpRedirectSection.Properties.Item("enabled").Value = True
httpRedirectSection.Properties.Item("destination").Value = "http://www.contoso.com"
httpRedirectSection.Properties.Item("exactDestination").Value = False
httpRedirectSection.Properties.Item("httpResponseStatus").Value = "Found"

adminManager.CommitChanges()

다음 코드 샘플은 ASP 파일에 대한 모든 요청을 웹 사이트의 홈페이지로 리디렉션하는 와일드카드 리디렉션 항목을 추가합니다.

참고

이 예제는 웹 사이트에서 모든 ASP 기반 애플리케이션을 제거하고 이전 애플리케이션에 대한 클라이언트 요청을 HTTP 404 찾을 수 없음 응답을 수신하지 않고 웹 사이트의 루트로 리디렉션하려는 경우에 유용합니다.

AppCmd.exe

appcmd.exe set config "Default Web Site" -section:system.webServer/httpRedirect /enabled:"True" /exactDestination:"True" /httpResponseStatus:"Found"

appcmd.exe set config "Default Web Site" -section:system.webServer/httpRedirect /+"[wildcard='*.asp',destination='/default.htm']"

C#

using System;
using System.Text;
using Microsoft.Web.Administration;

internal static class Sample
{
   private static void Main()
   {
      using(ServerManager serverManager = new ServerManager()) { 
         Configuration config = serverManager.GetWebConfiguration("Default Web Site");

         ConfigurationSection httpRedirectSection = config.GetSection("system.webServer/httpRedirect");
         httpRedirectSection["enabled"] = true;
         httpRedirectSection["exactDestination"] = true;
         httpRedirectSection["httpResponseStatus"] = @"Found";

         ConfigurationElementCollection httpRedirectCollection = httpRedirectSection.GetCollection();
         ConfigurationElement addElement = httpRedirectCollection.CreateElement("add");
         addElement["wildcard"] = @"*.asp";
         addElement["destination"] = @"/default.htm";
         httpRedirectCollection.Add(addElement);

         serverManager.CommitChanges();
      }
   }
}

VB.NET

Imports System
Imports System.Text
Imports Microsoft.Web.Administration

Module Sample

   Sub Main()
      Dim serverManager As ServerManager = New ServerManager
      Dim config As Configuration = serverManager.GetWebConfiguration("Default Web Site")

      Dim httpRedirectSection As ConfigurationSection = config.GetSection("system.webServer/httpRedirect")
      httpRedirectSection("enabled") = True
      httpRedirectSection("exactDestination") = True
      httpRedirectSection("httpResponseStatus") = "Found"

      Dim httpRedirectCollection As ConfigurationElementCollection = httpRedirectSection.GetCollection
      Dim addElement As ConfigurationElement = httpRedirectCollection.CreateElement("add")
      addElement("wildcard") = "*.asp"
      addElement("destination") = "/default.htm"
      httpRedirectCollection.Add(addElement)

      serverManager.CommitChanges()
   End Sub

End Module

JavaScript

var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site";

var httpRedirectSection = adminManager.GetAdminSection("system.webServer/httpRedirect", "MACHINE/WEBROOT/APPHOST/Default Web Site");
httpRedirectSection.Properties.Item("enabled").Value = true;
httpRedirectSection.Properties.Item("exactDestination").Value = true;
httpRedirectSection.Properties.Item("httpResponseStatus").Value = "Found";

var httpRedirectCollection = httpRedirectSection.Collection;
var addElement = httpRedirectCollection.CreateNewElement("add");
addElement.Properties.Item("wildcard").Value = "*.asp";
addElement.Properties.Item("destination").Value = "/default.htm";
httpRedirectCollection.AddElement(addElement);

adminManager.CommitChanges();

VBScript

Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Default Web Site"

Set httpRedirectSection = adminManager.GetAdminSection("system.webServer/httpRedirect", "MACHINE/WEBROOT/APPHOST/Default Web Site")
httpRedirectSection.Properties.Item("enabled").Value = True
httpRedirectSection.Properties.Item("exactDestination").Value = True
httpRedirectSection.Properties.Item("httpResponseStatus").Value = "Found"

Set httpRedirectCollection = httpRedirectSection.Collection
Set addElement = httpRedirectCollection.CreateNewElement("add")
addElement.Properties.Item("wildcard").Value = "*.asp"
addElement.Properties.Item("destination").Value = "/default.htm"
httpRedirectCollection.AddElement(addElement)

adminManager.CommitChanges()