fuel / core

Fuel PHP Framework - The core of the Fuel v1 framework
http://fuelphp.com
813 stars 345 forks source link

Uri string is trimed slash. #1314

Closed hackoh closed 11 years ago

hackoh commented 11 years ago

I encountered the following problem. My setting is below.

// in routes.php
return array(
    'rest/files/(.*)' => 'rest/files/index/$1',
    '_root_' => 'front/index/index',
    '(:segment)' => 'front/$1/index',
    '(:segment)/(:segment)' => 'front/$1/$2',
);

And access to http://localhost/rest/files/ then it matches below.

    '(:segment)/(:segment)' => 'front/$1/$2',

    // 'rest/files/(.*)' => 'rest/files/index/$1', does not match!!

I think that this cause is the following.

// CORE/classes/uri.php:247
        $this->uri = trim($uri ?: \Input::uri(), '/');

In the whole FuelPHP, although it seems that the slash of the end of URI is deleted, I think that the slash of the end in URI has an important meaning.

How do you think?

WanWizard commented 11 years ago

In a standard static website, the trailing slash indicates the difference between a filename and a foldername. When using a framework, that difference is not relevant, only URI segments are.

Therefore the trailing slash is trimmed to avoid confusion, and to prevent people from NOT wanting this strict behaviour to define all their routes twice (with and without the trailing slash).

You can solve this issue by using this route:

rest/files(/.*)' => 'rest/files/index$1',