URI Routing

Typically there is a one-to-one relationship between a URL string and its corresponding controller/handler. The segments in a URI normally follow this pattern:

example.com/controller/handler/id/

In some instances, however, you may want to remap this relationship so that a different controller/handler can be called instead of the one corresponding to the URL.

For example, lets say you want your URLs to have this prototype:

example.com/product/1/ example.com/product/2/ example.com/product/3/ example.com/product/4/

Normally the second segment of the URL is reserved for the handler name, but in the example above it instead has a product ID. To overcome this, revIgniter allows you to remap the URI handler.

# Setting your own routing rules

Routing rules are defined in your routes.lc file. In it you'll see an array called gRoute that permits you to specify your own routing criteria. Routes can either be specified using Wildcards or Regular Expressions.

# Examples

Here are a few routing examples:

put "blogs" into gRoute[2]["journals"]

A URL containing the word "journals" in the first segment will be remapped to the "blogs" controller.

put "blogs/users/34" into gRoute[3]["blog/joe"]

A URL containing the segments "blog/joe" will be remapped to the "blogs" controller and the "users" handler. The ID will be set to "34".

put "catalog/productLookup" into gRoute[4]["product/:any"]

A URL with "product" as the first segment, and anything in the second will be remapped to the "catalog" controller and the "productLookup" handler.

put "catalog/productLookupByID/$1" into gRoute[5]["product/(:num)"]

A URL with "product" as the first segment, and a number in the second will be remapped to the "catalog" controller and the "productLookupByID" handler passing in the match as a variable to the handler.

Important: Do not use leading/trailing slashes.

# See also

Here we describe how yo can use wildcards in revIgniter URI Routing.

Here we describe how yo can use regular expressions in revIgniter URI Routing.

There are three reserved routes: one each for the defaultController, the 404Override, and the scaffoldingTrigger.