Redirects behavior with /public folder

I have a site that is using a public folder with static HTML, because we are migrating our site which was originally in static HTML incrementally.

However, there is some strange behavior now that I’m trying to add redirects.

We have a page in our wordpress site that has the permalink (using custom permalinks plugin) set to ‘afr/index.htm’. Previously when hosting our static HTML site the url ‘afr/’ would route to using the index.htm. But currently it shows a ‘403 Forbidden’ error from nginx.

An interesting thing is if we go to a subfolder link, like ‘afr/mbi’, it will directly route to ‘afr/mbi/index.htm’. We tried added redirects via. the yoast pro SEO, and those work on normal wordpress pages, but they don’t work to redirect the 403 page to the main ‘index.htm’ page.

I noticed that yoast says it uses php redirects in the settings so this explains some things to me, and the redirects may not work with this approach of using the public folder. How can we achieve the desired behavior of redirecting these 403 pages to their corresponding ‘index.htm’ wordpress page?

Any help would be appreciated, it’s important to us that we fix this soon.

Thanks!

1 Like

I believe you would want your permalinks to be the directory path instead of the index.htm.
Previously with the static HTML pages the directory was routing to index.htm in that folder because of DirectoryIndex settings.

I’d imagine to complete the transition and cover any and all ways pages may have been linked in the past, you would use the directory path for permalinks and set up a redirect for any index.htm to go to the directory instead. Since some pages may have directly linked to the file instead of the directory before.

something like (.*)index.htm => $1

Thank you for the help.

I have done some testing.

When I set a permalink to the directory instead of the ‘index.htm’, I still seem to get the 403 error, as if there is some behavior (maybe nginx, or something different) taking precedent.

image
(setting permalink using custom perma-links plugin)

When I set the permalink to ‘afr/mbi/index.htm’ (subdirectory ‘mbi’ doesn’t exist). It works fine. When I set it to just ‘afr/mbi’ I get a 404 wordpress page as expected.

When I set the permalink to ‘afr/mlb/index.htm’ (mlb and mlb/index.htm exist) and navigate to the index.htm page, it goes to the static html file located in the public folder, because it seems to take precedent.

If I set it to ‘afr/mlb’, again it does nothing, same behavior as above. It seems to route to the index.htm.

So what is confusing is the behavior of top-level directories inside the public folder giving 403s. I’m guessing it has to do with the public folder/nginx because of the above behavior of those files taking precedent over the WordPress routing.

Hopefully, I gave all the details that are useful and this makes sense. I wonder if I can fix this…

I fixed my issue by defining redirects using the nginx-includes directory.

1 Like