301 redirect using a custom 404 handler - executes but has no effect
Hi there,
I'd like to redirect some of the paths on our domain that used to point to pages we had before using Umbraco, to the location of the new pages. We want to use redirection rather than URL rewriting.
For example, http://mysite.com/blog-old (which currently returns a 404, handled by Umbraco), should redirect to http://mysite.com/blog-new. The new link may not necessarily point to a node in Umbraco (i.e., it may be an external link).
To get a very general case working, I've written a custom 404 handler based on Morten's suggestion in this thread, which looks like this:
using System.Web; using System.Xml; using umbraco; namespace MyWebsite.NotFoundHandlers { public class PermanentRedirectHandler : umbraco.interfaces.INotFoundHandler { private int _redirectID = -1; public bool CacheUrl { get { return false; } } public int redirectID { get { return _redirectID; } } public bool Execute(string url) { HttpContext.Current.Response.Status = "301 Moved Permenantly"; HttpContext.Current.Response.AddHeader("Location", "http://www.google.co.uk/"); return true; } } }
To my understanding, this should just redirect every unmapped URL to Google, and I'm comfortable that I can work in specific pages later.
However, when I visit an unmapped URL, I always get the Umbraco 404 page. I've confirmed that the handler is being called with some logging, so I know the logic is being executed, but it's not having any effect on the resolution.
We're using 4.11.1, and I have seen mention of a related bug, which I assume affects us (it doesn't seem to be fixed for our version). Can anyone confirm this is the cause? And if I'm (hopefully) wrong about that, can anyone suggest what I might be doing wrong to prevent the handler from working?
However, this just gave me the regular 404 pages too. I'd be just as happy to use this approach if there's a way to make it work (or any other approach that works, of course :p).
301 redirect using a custom 404 handler - executes but has no effect
Hi there,
I'd like to redirect some of the paths on our domain that used to point to pages we had before using Umbraco, to the location of the new pages. We want to use redirection rather than URL rewriting.
For example, http://mysite.com/blog-old (which currently returns a 404, handled by Umbraco), should redirect to http://mysite.com/blog-new. The new link may not necessarily point to a node in Umbraco (i.e., it may be an external link).
To get a very general case working, I've written a custom 404 handler based on Morten's suggestion in this thread, which looks like this:
And added it into the 404handlers.config here:
To my understanding, this should just redirect every unmapped URL to Google, and I'm comfortable that I can work in specific pages later.
However, when I visit an unmapped URL, I always get the Umbraco 404 page. I've confirmed that the handler is being called with some logging, so I know the logic is being executed, but it's not having any effect on the resolution.
We're using 4.11.1, and I have seen mention of a related bug, which I assume affects us (it doesn't seem to be fixed for our version). Can anyone confirm this is the cause? And if I'm (hopefully) wrong about that, can anyone suggest what I might be doing wrong to prevent the handler from working?
I thought I'd also mention, I've tried adding the following lines to web.config (in place of the approach above):
<configuration>
...
<locationpath="~/blog-old">
<system.webServer>
<httpRedirectenabled="true"destination="http://www.google.co.uk"httpResponseStatus="Permanent"/>
</system.webServer>
</location>
</configuration>
However, this just gave me the regular 404 pages too. I'd be just as happy to use this approach if there's a way to make it work (or any other approach that works, of course :p).
is working on a reply...