skip to Main Content

all I am new to Lumen cause I was using something else before. I have tested Lumen project and find out that it works well with nice support and documentation and can be extend to Laravel which is a bigger project. So I decide to use Lumen for a company,

The only problem I am currently facing now is trailing slash of url on Nginx.
e.g.

$app->get('welcome', function() { return 'Hello'; });

it responds to

http://mysite.dev/welcome

but with a trailing slash

http://mysite.dev/welcome/

the site throws a 404.

This is because the old website been using all url with end slash for e.g. PPC, SEO … more, They do not want to redo and change the whole process including 3rd party who use these url and they can not do 301 from url with ending / to redirect to url without ending / which will cause too much redirection.

I have tried searching for solution for whole week now but still can not find any solution that best match this user requirement.

Is there any way for lumen to revert routing url to work with ending / and not working with without ending / ??

or otherwise could you please recommend me to use something else? To match this requirement.

I also tried this service provider still not working link

Regards

2

Answers


  1. Lumen and Laravel should be fine with trailing slashes.
    The 404 is likely resulting from a bad nginx configuration.

    This is how my nginx config looks like to catch the trailing slash and use the same content at that location.

    location / {
        index index.html index.htm index.php;
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    Login or Signup to reply.
  2. If you’re using Nginx, try this config:

    index  index.html index.htm index.php;
    location @rewrite {
        rewrite ^/(.*)$ /index.php;
    }   
    location / {
        try_files $uri $uri/ @rewrite;
    }
    

    I once encountered a similar problem,after debugging with RoutesRequest.php, I discovered that the 5.4 version no longer needs the $query_string or $args things(have no reason why most tutorials still have them).

    Hope this helps.If not, maybe you could try debugging with RoutesRequest.php too, adding some helpful outputs will certainly help you locate the problem.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search