Laravel routing how case insensitive

Source: Internet
Author: User
//D:/website/zbphp.com/www/Laravel/app/routes.phpRoute::group(array('prefix'=>'admin'),function(){    Route::get('login','admin\HomeController@login');});

http://localhost/ADMIN/LOGIN/error when URL is not accessible
How case insensitive

Reply content:

//D:/website/zbphp.com/www/Laravel/app/routes.phpRoute::group(array('prefix'=>'admin'),function(){    Route::get('login','admin\HomeController@login');});

http://localhost/ADMIN/LOGIN/error when URL is not accessible
How case insensitive

Force the route URL to all lowercase, in the main portal file server.php inside can be manipulated.

@kankana, Suit!

There's no good way to do this.
Well, you define route using pattern.
Refer here Http://stackoverflow.com/questions/21731151/laravel-case-insensitive-routes
Yes, you want LS to say, convert to lowercase.
The correct file to handle this kind of thing is app/filters.php rather than server.php (more than a portal file).

App::before(function($request){    $fullUrl = $request->fullUrl();    if(preg_match('@[A-Z]@', $fullUrl))        return Redirect::to(Str::lower($fullUrl));});

Another way to do this is to convert the case when the error occurs.
This is app/start/global.php.

App::error(function(Symfony\Component\HttpKernel\Exception\NotFoundHttpException $exception, $code){    $fullUrl = Request::fullUrl();    if(preg_match('@[A-Z]@', $fullUrl))        return Redirect::to(Str::lower($fullUrl));});

In fact, both of these methods are the next worst.

And why do I say server.php is not a portal file?

Because this is PHP's internal Web server, for details you can refer to, I will not say more.

Http://stackoverflow.com/questions/16919920/what-is-the-purpose-of-the-server-php-file-in-laravel-4

If you use Apache/nginx to run Laravel, you must point to public/index.php, not server.php. So if you say to LS that it is not possible to modify these operations directly in server.php, in a production environment (Nginx/apache).

By the way, artisan serve this command can start PHP's internal Web server, when server.php is the portal file.

This command file illuminate\foundation\console\servecommand.php
passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port} -t \"{$public}\" server.php");

Extend Router class Rewrite This method should be possible.
protected function Addroute ($methods, $uri, $action)
{
return $this->routes->add ($this->createroute ($methods, Strtolower ($uri), $action));
}

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.