I'd like to set up a 301 redirect from a .co.uk site to a .com site, keeping the same pages.
So someone going to mydomain.co.uk/pages/about should get redirected to mydomain.com/pages/about
I'm using ASP.NET and IIS 7.0 and not having much luck. I tried setting a custom 404 file that has a redirect in it like so:
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains(".co.uk"))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace(
".co.uk",
".com"));
}
however my 404 page isn't being called when I go to a URL such as /pages/about. I have the following in my web.config:
<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="404.aspx"/>
</system.web>
</configuration>
Can anyone assist please?