Wolen Wolen - 7 months ago 87
PHP Question

Laravel 5 bad behaviour while removing trailing slash

I've created a Laravel project under mywebsite.com/laravel/. When I go to mywebsite.com/laravel/test, everything is ok, but when I go to mywebsite.com/laravel/test/, I'm redirected to mywebsite.com/test.

I have the files index.php and .htaccess in my /laravel directory. This is my .htaccess file:

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

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteBase /laravel
RewriteRule ^(.*)/$ /$1 [L,R=301]

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

I have no idea why
doesn't work. I've tried /laravel, /laravel/ and laravel; nothing worked.

My routes.php file

Route::get('/test/{name?}', 'MainController@index');

Route::group(['middleware' => ['web']], function () {


The solution is change

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


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

And in my case clear cache in my browser :).