Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the gd-bbpress-attachments domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/mxvysmpn/public_html/wp-includes/functions.php on line 6121

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the nextgen-gallery-pro domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/mxvysmpn/public_html/wp-includes/functions.php on line 6121
Ready to use 301 Redirect with Http Module | Ready to use 301 Redirect with Http Module – { Dev Farm }

{ Dev Farm }

Web & Windows Development

Ready to use 301 Redirect with Http Module

| 1 commento

[wpdm_file id=2]

Just open the web.config and edit the appsetting newSite with your new site. That’s all!

All the requests will be forwarded with “301 Moved Permanently” status code.

Example: Your site is published at http://www.currentsite.com and you want to redirect at http://www.newsite.com

upload the files at http://www.currentsite.com and edit the web.config like:

www.newsite.com"/>

All request will be forwarded like:

http://www.currentsite.com
-> http://www.newsite.com

http://www.currentsite.com/helloworld
-> http://www.newsite.com/helloworld

 

 

The site is tested on iis7, framework 4 Integrated pipeline mode (standard configuration in most of cases).

Source Code:

——————————— Web.config


——————————— Module.cs

using System;
using System.Web;
using System.Configuration;

namespace Redirect
{
public class Module : IHttpModule
{

public void Dispose()
{
}

public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(Application_BeginRequest);
context.EndRequest += (new EventHandler(Application_EndRequest));
}

private void Application_BeginRequest(Object source, EventArgs e)
{
HttpApplication hap = (HttpApplication)source;
HttpContext hc = (HttpContext)hap.Context;
string newSite = ConfigurationManager.AppSettings["newSite"];
string strUrl = newSite + hc.Request.Url.PathAndQuery;
hc.Response.Clear();
hc.Response.Status = "301 Moved Permanently";
hc.Response.Headers.Add("Location", strUrl);
}

private void Application_EndRequest(Object source, EventArgs e)
{

}

}
}

 

Un commento

Lascia un commento

I campi obbligatori sono contrassegnati con *.