Is it possible for FuelPHP not to allow the right side of the route?
-
28-05-2021 - |
题
In config/routes.php
<?php
return array(
'account/profile/change_password' => 'users/account/change_password',
);
I can access site.com/users/account/change_password
and site.com/users/account/change_password
in the browser.
Is there a way to restrict it to the left side only (i.e. site.com/users/account/change_password
)?
解决方案
Only by routing it specificly, for example by routing it to the same place as your _404_
controller. Of course you could also do it for the entire controller:
'users/account(/:any)' => 'my/404/route',
That way a direct call on this controller would always go to your 404.
Of course if your routes end in a wild-card route like ':any' => 'catch/everything/$1'
you don't need to do this.
其他提示
To be complete: if you want to allow only HMVC calls, but no URI access, you can also capture it in the controller itself. Either in the before() method (for the entire controller) or in the individual methods:
// throw a 404 if accessed via the URI
if ( ! \Request::active()->is_hmvc())
{
throw new \HttpNotFoundException();
}