Search code examples
reactjsapachegatsbyampps

I copy the files that the gatsby build gives to ampps/www/my-site but the links not work


I create a new site using the gatsby-cli. Then I just build the site, then, all the content that is inside the build I copied to my AMPPS/www/my-site folder. When I access to the site, the index works correctly but when I click on a route to go to another route I got the following error: The requested URL /page-2/ was not found on this server..

I understood that gatsby will generate an static HTML site, and the production server where I need to place the build only accepts an static HTMl site. So is there a way to achieve a truly server side rendering with gatsby?

Thanks in advance.


Solution

  • The solution is quite simple:

    If apache serves ampps/www/my-site as http://localhost/my-site you need to use path-prefix, by default gatsby assume it will be hosted at root of domain.

    To enable this features, we just need to use the following documentation: https://www.gatsbyjs.org/docs/path-prefix/