How to serve all routes on a production server exactly?

I think I understand for a little now, since a url like http://domain.com/posts/new which the /posts/new part doesn’t exists for Nginx, so 404 does make sense. (Although I still don’t know why localhost don’t care, anyone knows?)

So maybe the simplest solution is to add a rewrite rule for Nginx, for now I am trying this one:

server {
    listen 80 default;
    server_name my.domain.com;
    root /path/to/app/root;

    rewrite ^(.+)$ /index.html last;
}

However this rule also rewrites all requests to files under /assets folder, I am searching for a solution but no luck so far. Does anyone knows how to solve this? or I’m just completely wrong?

1 Like