You cannot achieve your goal by simply rewriting. Laravel always knows about the real URI .
The key point is that you need to process all requests with only one route. Laravel uses the variable $_SERVER['REQUEST_URI'] for routing and is passed to Laravel from fastcgi . The REQUEST_URI variable is set in the fastcgi_params file from the nginx $request_uri variable:
fastcgi_param REQUEST_URI $request_uri;
Therefore, you need to pass REQUEST_URI as / in Laravel to handle the request /bla/bla , since this is / .
Just add one line to the configuration:
location ~ \.php$ {
If you have /api/ , you need some changes for the line:
set $request_url $request_uri; if ($request_uri !~ ^/api/(.*)$ ) { set $request_url /; } fastcgi_param REQUEST_URI $request_url;
Nginx warns that if is evil, this is just the first idea.
Summarizing:
/ goes to the Laravel route / .
/api/* go to Laravel route routes.
Other requests go to the Laravel / route.
source share