• Hello, several years ago, I developed a simple plugin to display an archive of PDF files grouped by year. While I can’t pinpoint the exact time it stopped working, it was definitely within the past few months. The problem is that an unwanted redirect is happening before my plugin even sees the URL.

    If you visit this URL: /profile/, you’ll see a list of years on the right hand side. Every single one of those links simply adds a year to the URL. For example: /profile/2018/, but it redirects back /profile/ every time.

    As I mentioned, this only started happening recently, so I’m wondering if anyone might know where this redirect is coming from. I’ve tried the Redirection plugin in the hopes that it would log the redirect, but it did not. I understand that this might be a problem with the theme (Divi), but I thought I’d ask here first.

    • This topic was modified 5 years, 9 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I believe it is redirect_canonical(). It’s redirecting because it cannot find a sub-page /profile/2018/, so it’s serving the closest fit it can find. You can likely suppress the behavior through a filter by the same name. It’s kind of a hacky solution though. What you want is a rewrite rule that explicitly defines the URL structure you want and rewrites the request as an URL query string, for example index.php?pagename=profiles&p-year=2018.

    The “profiles” page would be based on a custom template that gets the “p-year” query var and does something to fulfill the request for that year. I purposely used “profiles” plural to differentiate from the existing page, but the “profile” page template could handle this just as easily. If there is no p-year query var, it does what it does now. If there is a query var, it can do something else.

    Thread Starter PBenz

    (@pbenz)

    Thank you, bcworkz. After playing around with this a bit, I think you are correct in that this is related to redirect_canonical(). What’s disheartening is that these pages were working just fine for the past 5 years or so – this only started happening recently.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Help with unwanted redirection’ is closed to new replies.