Wolen Wolen - 10 days ago 5
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
</IfModule>

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
RewriteBase
doesn't work. I've tried /laravel, /laravel/ and laravel; nothing worked.

My routes.php file

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

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

Answer

The solution is change

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

to

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

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

Comments