Sonu's avatar
Level 3

Why Laravel 5 is Redirecting when I put slash at the end of URL?

When I try this

http://localhost/2ndApp/users/login

it works. But when I try

http://localhost/2ndApp/users/login/

it redirects me to

http://localhost/users/login/

Any idea why?

0 likes
7 replies
RemiC's avatar

The rewrite rules should normally trim the ending slash and redirect you to the the correct route.

Is your 2ndApp another Laravel app in a subfolder ?

Sonu's avatar
Level 3

No @RemiC 2ndApp is The Main Folder Where Laravel Is Installed

RemiC's avatar

You should install it so the root of your localhost is the laravel /public directory.

1 like
pmall's avatar
pmall
Best Answer
Level 56

@Sonu your virtualhost must have the public folder as root

1 like
jjudge's avatar

@RemiC that seems a bit restrictive - only one Laravel instance can be installed for any domain. The public files for an installation should work from any directory you like. It always did on Laravel 4, so what has changed with L5, apart from the assumption that a domain will be hosting exactly one Laravel installation in the root directory.

jjudge's avatar

Found the solution here:

http://stackoverflow.com/questions/22063520/laravel-slash-after-url-redirects-to-root-folder

Basically the .htaccess that laravel ships with will redirect any matching path with a trailing slash to "/path". You can get away with it using a RewriteBase and setting that rewrite rule to use that base. So now you have this in .htaccess:

RewriteRule ^(.*)/$ /$1 [L,R=301]

That needs to be changed (for the OP example) to this:

RewriteBase /2ndApp
RewriteRule ^(.*)/$ $1 [L,R=301]

This assumes that "2ndApp" is the directory that starts its life as "public" when you first install Laravel.

The RewriteBase would need to be set differently for each installation into different root directories, but does the job.

2 likes

Please or to participate in this conversation.