patronage / bubs-next

Headless Wordpress + Next.js Project scaffolding
https://bubs-next.vercel.app
MIT License
37 stars 10 forks source link

404 paths returning wrong redirect #244

Closed ccorda closed 1 year ago

ccorda commented 1 year ago

When requesting /foo on the origin, had an instance on a recent site where headless redirect was returning the slug of the most recent post.

Not sure if this is widespread, as I wasn't seeing this on other sites (need to test if we can recreate).

Solve ended up being to add a specific check:

// if a 404 quickly fail and send to headless domain to handle
  // if we don't, WP will return info on a post we don't want (e.g. the most recent post)
  if (is_404()) {
    $redirect = $headless_domain . $path;
    return $redirect;
  }
ccorda commented 1 year ago

Able to duplicate here:

curl -I https://bubsnext.wpengine.com/foo
HTTP/2 307 
server: nginx
date: Thu, 09 Feb 2023 23:15:24 GMT
content-type: text/html; charset=UTF-8
content-length: 0
location: https://bubs-next-git-sitemaps-robots-patronage.vercel.app/posts/kitchen/
x-powered-by: WP Engine
link: <https://bubsnext.wpengine.com/wp-json/>; rel="https://api.w.org/"
expires: Wed, 11 Jan 1984 05:00:00 GMT
x-redirect-by: WordPress
x-cacheable: non200
cache-control: max-age=600, must-revalidate
x-cache: HIT: 1
x-cache-group: normal
x-orig-cache-control: no-cache, must-revalidate, max-age=0