Routing/Redirect issues after moving from apache to nginx

I am having a routing problem migrating from apache to nginx (using SEO Tab/Suite):

  • /blog/category/article.html)is set in 301 redirects
  • correctly redirects to /blog/category/2021/10/29/article/ (set via freeze URL)

After migrating to nginx this redirect is not working anymore. I’m getting a 404. When I change the 301 redirect to something like this /path/does/not/exist/article.html it is working again.

So it looks like nginx can’t resolve the path correctly when it matches an existing path. I am using the example nginx configuration from modx docs (Nginx Server Config - Using Friendly URLs | MODX Documentation). Any ideas?

I’m somewhat confused by your description and don’t really understand what you’re doing.

What do you mean by “an existing path”? An actual .html file that exists on the disk?

If you call the target-url of your ‘301 redirect’ directly, does that work? Meaning, is it a problem with SEO Tab or a problem with the Nginx server config?

Which extra do you use exactly? SEO Suite or SEO Tab?

I can reproduce this using SEO Tab and SEO Suite (reproduced with both). I forgot to mention that this only applies to the Articles extension which sets freeze url for articles.

How to reproduce this issue:

  1. Install MODX with SEO Suite and Articles on LEMP Stack (using MODX docs nginx configuration file)

  2. Create an ArticlesContainer called blog

  3. Inside blog create an article set to unpublished => URL will be /blog/test-article.html

  4. Publish article => URL will change to /blog/2021/10/29/test-article.html

  5. Redirect 301 will be automatically added for /blog/test-article.html

  6. Open this url
    => MODX returns 404 instead of 301

  7. Modify the path of the 301 redirect to something that doesn’t exist for example /does/not/exist/test-article.html

  8. Open this url
    => MODX returns 301 and redirects to the article

So you are saying that in step 8 you open the url that then redirects you to and that shows you the correct content of the resource with the frozen url

That doesn’t make any sense.

What happens if you call directly?
What happens if you call directly?

It seems to me to be more a problem with the cache.

Have you cleared the MODx cache between these tests?
Are both extras (SEO Tab and SEO Suite) installed simultaneously on the same MODx installation?

Sorry, this is confusing. Let me clarify. Cache is cleared, only SEO Suite is installed.

Freeze URL set by Articles extension is:

Added as redirect 301 url for this is: (unpublished URL from Articles extension)

When I call /blog/test-article.html directly it returns error 404.

When I alter this url in redirect 301 to and call this it redirects correctly to /blog/2021/10/29/test-article/

Maybe my workflow/steps to reproduce are too complicated. To simplify it:

  • Article resource freeze url is /blog/category-a/this-is-the-current-url.html

  • Add 301 redirect for this /blog/category-a/some-other-url.html

When calling /blog/category-a/some-other-url.html it should redirect to /blog/category-a/this-is-the-current-url.html but it doesn’t. It returns 404. (not working with nginx, but working with apache)

  • Add 301 redirect for this /path/not/exists/category-a/some-other-url.html

When calling this, it redirects correctly to /blog/category-a/this-is-the-current-url.html

All these redirects are done inside MODx, so it’s weird that it works for apache but doesn’t for nginx.

Maybe the problem is the order in which the plugins for Articles and SEO Suite are called. Both plugins run on the event “OnPageNotFound”.

Try changing the priority of the plugins, so that the plugin for SEO Suite runs first (has a lower number).

There is a column “Priority” in the tab “System Events” of the plugin for that:

Thanks so much for this tip!!! It’s working now. ArticlesPlugin needs to run after SEO Suite. So I set priority of ArticlesPlugin for OnPageNotFound to 1.

Seems like this has nothing to do with Apache vs Nginx. I guess the order in which extensions/plugins are installed in MODX does matter in terms of what gets executed first when priority is set to 0. So in my apache test system I just installed articles before seo suite than… :exploding_head: