Serve an external PHP system through a sub directory of a Netlify Next.js website

Hello

We have a main website running using Next js on Netlify (https://www.greystone-engineering.com/) and we have a PHP (Laravel) service running on a sub domain (https://directory.greystone-engineering.com/).

Ideally we would like to run it on https://www.greystone-engineering.com/members-directory. Is there anything in Netlify than can manage this for us?

Hey @snips11

Check out the Proxy to another service section of the Rewrites and Proxies documentation which shows how to achieve exactly what you are wishing to do :slight_smile:

Thanks for your help @colemay

I have added the following to the redirects in the netlify.toml file

[[redirects]]
  from = "/members-directory/*"
  to = "https://directory.greystone-engineering.com/:splat  200"
  status = 200
  force = true

But it is still getting a 404 when I go to https://www.greystone-engineering.com/members-directory

Could I be missing something?

This line is incorrect

Should read

to = "https://directory.greystone-engineering.com/:splat"

Thank you so much, thats great. Nearly all working, just one last question…

[[redirects]]
  from = "/members-directory"
  to = "https://directory.greystone-engineering.com"
  status = 200
  force = true

When using the above the route works perfectly but the url removes the /members-directory so makes it look like its loaded in the root. Is there a way of getting the correct content but maintaining the /members-directory? I guess you could always reflect that in the Laravel application and then again over here in the from but is there an easier way?

This is strange behaviour. I am thinking this is something to do with Next.js. as it is not a known internal route. My knowledge of Next.js is limited so I do not know if there is a way to stop it.

An alternate method (perhaps) it to integrate the directory directly into the main site, fetching data from https://directory.greystone-engineering.com rather than displaying it as a site.