Geta / geta-notfoundhandler

The popular NotFound handler for ASP.NET Core and Optimizely, enabling better control over your 404 page in addition to allowing redirects for old URLs that no longer works.
Apache License 2.0
20 stars 16 forks source link

AutomaticRedirectsEnabled setting set to false still create redirects for moved/renamed pages #130

Open efraimlorenzana opened 2 months ago

efraimlorenzana commented 2 months ago

Hi there,

I'm using this package to handle NotFound redirects in our Optimizely CMS project. I’ve run into an issue where setting "AutomaticRedirectsEnabled" to false doesn’t seem to stop redirects from being created when I move or rename a page.

What I have in the configuration: services.AddOptimizelyNotFoundHandler(o => { o.AutomaticRedirectsEnabled = false; });

What I Expected: No automatic redirects should be created when AutomaticRedirectsEnabled is set to false.

What Actually Happened: Redirects are still being created automatically even though I’ve disabled that feature.

Environment: Optimizely CMS Version: 12.30.0 Geta.NotFoundHandler.Optimizely Version: 5.0.8 .NET Core Version: net6.0

I’ve double-checked the documentation, and it seems like this should be working, so I’m not sure what’s going wrong. Any chance you could take a look?

Thanks!

jevgenijsp commented 3 weeks ago

Yes, this should work. Maybe you left this flag enabled from the appsettings.json? And that's why it gets overwritten.

  "Geta": {
    "NotFoundHandler": {
      "Optimizely": {
        "AutomaticRedirectsEnabled":  true
      }
    }
  }
efraimlorenzana commented 2 weeks ago

Hello,

No we never add this settings in our appsettings.json file, we have configured it via services as below:

services.AddOptimizelyNotFoundHandler(o => { o.AutomaticRedirectsEnabled = false; });

jevgenijsp commented 2 weeks ago

I checked in the sandbox app, and the move event stops firing if AutomaticRedirectsEnabledis set to false.

Could you also check whether a record is always created in the ContentUrlHistory table when content is moved?

I suggest also disabling the following two jobs that are related to Automatic Redirects:

efraimlorenzana commented 2 weeks ago

Hello, as per checking, the two scheduled jobs are not running automatically either, and no the content that was moved are not created in the ContentUrlHistory. I can reproduce the issue both in my local project and also in live environment.

jevgenijsp commented 2 weeks ago

Thank you for testing and providing information.

Here’s how automatic redirects actually work:

When content is moved, a record is created in the ContentUrlHistorytable. A job or background service then checks the records in this table to generate redirects.

Maybe we are talking about different things? From your previous comment, it seems that ContentUrlHistorywasn’t affected. How did you identify that the problem exists?

efraimlorenzana commented 2 weeks ago

Let me share my perspective on how the issue appears from my end. When I create a new page (e.g., /wecare), it is saved in the ContentUrlHistory table with the following information: [{"Url":"/we-care/","Type":"Primary","Language":"en-GB"}].

If I then rename the page to /we-care-2 and check the NotFound Handler Redirects, I notice that a new entry is automatically created for this URL (Old URL: https://jderetail-test-whitelabel.jdecoffee.net/we-care/ & New URL: https://jderetail-test-whitelabel.jdecoffee.net/we-care-2/). Since AutomaticRedirectsEnabled is set to false, I wouldn’t expect redirects to be created automatically for any renamed URL, but that seems to be happening here.

Additionally, when I check the database, I don’t see any data reflecting /we-care-2; only the original entry from when the page was first created is present: [{"Url":"/we-care/","Type":"Primary","Language":"en-GB"}].

Given this outcome, do you think we might be looking at the issue from different perspectives?

jevgenijsp commented 2 weeks ago

Based on the previous comment, it appears that the AutomaticRedirectsEnabledflag is set to enabled. I don't have any other ideas at the moment.

You could try replicating this issue in the sandbox app included in the package, or debug the initialization of Geta.NotFoundHandler.Optimizely.Core.AutomaticRedirects.ContentUrlHistoryEvents in your solution to check if the events are being registered.