Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write a route to catch *.php?

I want to make a route that catches all "php" files... I've tried:

routes.MapRoute("php", "{*x}.php", new { controller = ... });

But I get the following exception:

A path segment that contains more than one section, such as a literal section
or a parameter, cannot contain a catch-all parameter.
Parameter: routeUrl

It must catch:

/p1/p2/p3.php
/p1/p2.php
/p1.php

I want to write a single rule that can catch N levels... How can I do that?

like image 456
BrunoLM Avatar asked Aug 25 '11 18:08

BrunoLM


People also ask

How do routes work in php?

Using a routing system allows us to structure our application in a better way instead of designating each request to a file. A routing system works by mapping an HTTP request to a request handler based on the request method and path specified in the URL of the request.

How can I get current route in Laravel?

Accessing The Current RouteThe Route::current() method will return the route handling the current HTTP request, allowing you to inspect the full Illuminate\Routing\Route instance: $route = Route::current(); $name = $route->getName();

How can I get current route in opencart?

In order to catch the current route, you can use $this->request->get['route']; in the catalog/controller/common/header.


1 Answers

You can use a constraint:

routes.MapRoute("php", "{*allphp}", new { ... }, new { allphp = @".*\.php" });

If you still have the default route, this must be placed before.

My answer is based upon: Make routing ignore requests for a file extension

like image 186
Laurent Avatar answered Oct 17 '22 00:10

Laurent