skybrud / Skybrud.Umbraco.Redirects

Redirects manager for Umbraco.
https://packages.limbo.works/skybrud.umbraco.redirects/
MIT License
38 stars 43 forks source link

Skybrud Redirects does not redirect when Error404Collection is set up #169

Closed vkuybida closed 1 year ago

vkuybida commented 1 year ago

Which version of Skybrud Redirects are you using? (Please write the exact version, example: 4.0.8)

4.0.8

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

11.2.2

Bug description

Skybrud Redirects does not redirect when Error404Collection is set up. It shows 404 error. Without 404 redirects it works fine.

GC-JamesShelley commented 1 year ago

@vkuybida I am running into the same issue. I have just noticed that when using Error404Collection, even though this functionality does work and the custom page shows, it is actually setting the status code to 200, not 404 like the default one does.

I have feeling this is what is causing the redirects to not work, as obviously if there was a successful 200 response, skybrud would just ignore (as expected).

I am just looking into why Error404Collection sets a 200 response at my end right now, if i find anything I will post here and let you know.

vkuybida commented 1 year ago

thanks.

at this point, as workaround, I implemented custom ContentLastChanceFinder where handle Skybrud redirects and 404 errors. It works fine.

Task IContentFinder.TryFindContent(IPublishedRequestBuilder request) { .....

#region Resolve Skybrud redirects

// Skybrud redirects
if (_redirectsService.GetRedirectByUri(request.Uri) != null)
{
    return Task.FromResult(false);
}

#endregion

#region Resolve 404 page

.....

var notFoundPage = siteRoot.Children.FirstOrDefault(x => x.Name == "404");

if (notFoundPage != null)
{
    request.SetIs404();
    request.SetPublishedContent(notFoundPage);
    return Task.FromResult(true);
}

#endregion

return Task.FromResult(false);

}

abjerner commented 1 year ago

This is an issue with Umbraco, as it accidentally sets a 200 OK status code. It should be fixed in 11.3, which was out earlier today:

https://github.com/umbraco/Umbraco-CMS/issues/13907

vkuybida commented 1 year ago

This is an issue with Umbraco, as it accidentally sets a 200 OK status code. It should be fixed in 11.3, which was out earlier today:

umbraco/Umbraco-CMS#13907

great to hear, thanks for the info

GC-JamesShelley commented 1 year ago

This is an issue with Umbraco, as it accidentally sets a 200 OK status code. It should be fixed in 11.3, which was out earlier today:

umbraco/Umbraco-CMS#13907

Awesome thanks @abjerner - yes I've just confirmed upgrading to Umbraco 11.3 now correctly sets a 404 when using Error404Collection, meaning Skybrud now works as expected. Thanks for your help and the great package. 👍