Domain redirect doesn't work

site name: istio.io

Redirect from a subdomain is not working correctly.

Here is my redirects file. Specifically lines 52 to 55. Sadly I can’t paste here since it’s complaining that I can only paste 6 links in a post. https://github.com/istio/istio.io/blob/master/layouts/index.redir#L52

If I navigate to archive.istio.io/v1.5, I get correctly redirected to istio.io/v1.5. The problem is that the other rule (redirect from archive.istio.io to istio.io/archive) is not working correctly. It seems like the domain is just displaying the main page without doing any redirects.

Hey @davidhauck! :wave:t2:

So a few things with the following -

http://archive.istio.io/ http://istio.io/archive 301!
http://archive.istio.io/* http://istio.io/:splat 301!
https://archive.istio.io/ https://istio.io/archive 301!
https://archive.istio.io/* https://istio.io/:splat 301!

For starters, you don’t ever need to write redirects from HTTP to HTTPS - Netlify does that automatically and the redirects engine begins after the request is transitioned to HTTPS. So we can always just write redirects assuming HTTPS

So that gets us to:

https://archive.istio.io/ https://istio.io/archive 301!
https://archive.istio.io/* https://istio.io/:splat 301!

So I checked some things from CLI and can confirm that hitting archive.istio.io/anything will do the splat redirect (second one) but just hitting the plain domain won’t redirect at all. Honestly I think there’s some clashing happening between those two rules because technically the from in the first one (https://archive.istio.io/) does actually meet the match pattern for the second (https://archive.istio.io/*) since the wildcard can represent nothing.

Your specific redirection need - to redirect to /archive if hitting the archive subdomain with no path, otherwise redirecting to /path if hitting the archive subdomain with a path is unique for sure.

Is there a way you could refactor some things to fit this instead? I think this may be more effective, though I understand that could require some real work!

https://archive.istio.io/* https://istio.io/archive/:splat 301!


Jon

Hey Jon, thanks for the reply! That’s pretty much what I thought. Sadly, adding your last suggestion isn’t possible. versioning needs to happen at istio.io/{version}. archive.istio.io is an old link that people have bookmarked and linked to, so that needs to go to the same page with a list of versions.

So that means I need archive.istio.io to redirect to istio.io/archive, and if there is a path after archive.istio.io, then I need that to go to istio.io/:splat.

Tricky! Good thing I love tricky :grin:


Maybe we just need to be smarter than the redirects engine :slight_smile: How about a masked Function?

https://archive.istio.io/* https://istio.io/.netlify/functions/archiver/:splat 200!

Then have a function like

archiver.js:


exports.handler = async (event, context) => {
  if (/\/$|^$/.test(event.path)) {
    return {
      statusCode: 301,
      headers: {
        Location: "https://istio.io/archive"
      }
    }
  }
  else {
    return {
      statusCode: 301,
      headers: {
        Location: `https://istio.io${event.path}`
      }
    }
  }
}

(I wrote this entirely in the Community markdown editor, so no claims for perfection on the syntax :rofl:)

Since the function is executed as a rewrite (200 status), the browser/user would never see it running through a backend Function and should be pretty workable! What do you think?


Jon