home / software / tips and tricks / How can page redirect or website redirect be done using the web.config file?

How can page redirect or website redirect be done using the web.config file?

Updated:  02/02/2012 13:02 PM
Author:  Shiju Mathews

Status:    Resolved.


In situation where we need page or the whole site to be redirected to another page on the same site or to a diffrent web site, web.cofig file can be a solution.The element configures settings for Internet Information Services (IIS) that redirect client requests to a new location.

Compatibility:
IIS 7.5 The element was not modified in IIS 7.5.
IIS 7.0 The element was introduced in IIS 7.0.
IIS 6.0 The element replaces the IIS 6.0 HttpRedirect metabase property.

Web.config Add a child element httpRedirect to the element.


httpResponseStatus value can be

Found: Returns a 302 status code, which tells the client to issue a new request to the location specified in the destination attribute.

Permanent: Returns a 301 status code, which informs the client that the location for the requested resource has permanently changed.

Temporary:Returns a 307 status code, which prevents the client from losing data when the browser issues an HTTP POST request.
Default value is 'Found'

1. Redirect current site to a new website.


wildcard redirection:

The following configuration sample adds a wildcard redirection entry that redirects all requests for ASP files to the home page of your Web site.

Attributes:
childOnly, destination, enabled, exactDestination,httpResponseStatus

Tags: How can page redirect or website redirect be done using the web.config file?
Updated on: December 2024