Nathi's avatar
Level 2

Lumen with trailing slash from URL using Nginx

Hi, 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 / ??

Regards

0 likes
1 reply
salmon's avatar

It works fine on my side with or without the trailing / but have you tried to add a trailing / at the end ?

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

Please or to participate in this conversation.