namespace
namespace

Reputation: 444

Laravel 4.2 Trailing Slash leads to base uri

I have a problem and I still can't fix that. I know that there are similars question here on SO, but nothing of that worked.

I use restful controllers. When I visit http://localhost/project/public/subsite it works. But when I visit http://localhost/project/public/subsite/ it redirects me to http://localhost/subsite

This is my current .htaccess file:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

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

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L] </IfModule>

I already tried solutions from these questions: laravel trailing Slashes redirect to localhost mod_rewrite remove trailing slash not working in Laravel

But the problem remains the same.

Upvotes: 0

Views: 824

Answers (2)

wizardofkoz
wizardofkoz

Reputation: 111

RewriteBase /project/public/

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

It worked for me to omit the slash that Cryode pointed to. Also be sure to clear your browser cache otherwise the changes may not take effect.

Upvotes: 1

Aken Roberts
Aken Roberts

Reputation: 13467

Try adding a RewriteBase:

RewriteEngine on
RewriteBase /project/public/

Essentially, when you specify the beginning slash in your rewrite line:

#                   V----- This little guy
RewriteRule ^(.*)/$ /$1 [L,R=301]

It says "go to this URL, starting from the root". Since your root is http://localhost, it starts from there, not from your project's root.

Upvotes: 0

Related Questions