I'm trying to create an IIS rewrite rule that will redirect all invalid blog post URLs back to the blog root. The problem is, my rule cannot detect when a URL actually exists, the negate conditions are not matched. I'm guessing because the rewrite rules are processed before Umbraco does any routing. Any ideas how to accomplish this? Can the UrlRewritingNet module handle this scenario? Or, would I be better to write a ContentFinder?
Of course, this will return a piece of content at the requested URL. If you want to get a redirect back to your home page then you'll need to add the redirect to the controller.
Thanks David. I wanted to return a 301 Redirect rather than a 404 so I went with the content finder as follows, (inserted just before the 404 Handlers) :
public class BlogNotFoundContentFinder : IContentFinder
{
public bool TryFindContent(PublishedContentRequest request)
{
// Get the requested URL path + query
var path = request.Uri.PathAndQuery.ToLower();
if (path.StartsWith("/blog/"))
{
// We only reach this point after normal Umbraco routing has not found content, so
// Set the 301 redirect on the request and return
request.SetRedirectPermanent("/blog");
return true;
}
return false;
}
}
IIS rewrite to catch all 'invalid' Umbraco URLs
I'm trying to create an IIS rewrite rule that will redirect all invalid blog post URLs back to the blog root. The problem is, my rule cannot detect when a URL actually exists, the negate conditions are not matched. I'm guessing because the rewrite rules are processed before Umbraco does any routing. Any ideas how to accomplish this? Can the UrlRewritingNet module handle this scenario? Or, would I be better to write a ContentFinder?
My web.config rewrite rule:
You're definitely better using an IContentFinder, as you say your IIS rewrite has no idea what Umbraco content exists or not.
Of course, this will return a piece of content at the requested URL. If you want to get a redirect back to your home page then you'll need to add the redirect to the controller.
Thanks David. I wanted to return a 301 Redirect rather than a 404 so I went with the content finder as follows, (inserted just before the 404 Handlers) :
Hope this helps others in a similar situation!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.