Router

Developer

Isaac Raway - Airways

3rd Party (Free)

GNU General Public License v3

EE Version Support

  • ExpressionEngine 2

Compatibility

If an item is crossed out, it might be untested, not applicable or incompatible. Contact the developer to be sure.

  • Updater
  • Multi Site Manager
  • Stand Alone Entry Form
  • Low Variables
  • Content Elements
  • Better Workflow
  • Matrix
  • Grid
  • Webservice
  • Publisher

Requirements

  • jQuery for the Control Panel

Add-On Type(s)

Plugin

Tags

Router is a regular expression based routing system for ExpressionEngine requests. It allows you to define any custom URL route you like, without needing to worry about template naming and without using large conditional checks.

New!! Now open source! GitHub page coming soon.

Router will automatically include the correct template for you, based on which of your regex patterns match the current URL. This can help avoid massive conditional {if} trees.

Never say “no” to a dream URL structure again!

Router will allow you to create the ultimate flexible URLs:

     
  • Easily redirect legacy URL patterns to new URLs
  •  
  • Include an extension such as .html at the end of article URLs
  •  
  • Include an unlimited number of categories in a URL
  •  
  • Have optional segments in the middle of URLs
  •  
  • Insulate your templates from the position of values within a URL - using names like {router_url_title} instead of {segment_5} in one case or some other segment in another case
  •  
  • Anything you can think of - Router will allow you to handle any URL structure you want

Compatible with Structure and others

Typically you should place the call to {exp:router:route} within your site/index template, and allow it to process all requests that do not match other templates. Real template groups, the member trigger, etc. do not need to be mapped in your routes file since EE will handle them and the request will never get to site/index nor therefore Router.

Or standalone

Of course Router can also completely stand on it’s own, allowing you to get a rich URL structure without needing any other add-ons or using anything more complex than your own categories and URL setup.

Usage

The tag takes a single parameter - the template to embed if no route is found. All other settings are set in the routes.ini file.

{exp:router:route no_route=“site/no_route”}

Because Router is included at the step of loading the default site template, it can be used in combination with any other add-on that modifies routes, including Structure, Freebie, and others.

Routes File

All routes are configured through an ini file placed here:

system/expressionengine/config/routes.ini

Route Syntax

pattern = “template_group/template_name” optional=“parameters” go=“here”

You may use any global or segment variables in the optional parameters, as well as variables created by Router itself of course.

Named Matches

Named matches such as (?P<name_here>.*) result in variables with appropriate names, in this case if this is the first match it will create two variables:
  {router_1}
  {router_name_here}

Defaults

Defaults for these values can be created in the [defaults] section of the file, which is optional.

Comments

Comments begin with a # symbol and must appear on their own line.

Categories

Router will look up any named matches and try to find a category with the same name. If it finds one, it will create variables that begin with the match name. In the above example, if a category matched for {router_name_here} you would also get these variables:

{router_name_here_category_id}
{router_name_here_category_parent_id}
{router_name_here_category_group_id}
{router_name_here_category_name}
{router_name_here_category_url_title}
{router_name_here_category_description}
{router_name_here_category_image}

Example Routes File


[defaults]
cat1 =
cat2 =
url_title =
club =
year = 0
month = 0
day = 0


[routes]
##
## home
##
^/*$ = "site/_home"

##
## normal sections
##

# main section
^(?P<cat1>.+)/*$ = "sections/_section" categories="{router_cat1_category_id}" title="{router_cat1_category_name}"

# main section month archive
^(?P<cat1>.+)/(?P<year>\d+)/(?P<month>\d+)/*$ = "sections/_section" categories="{router_cat1_category_id}" title="{router_cat1_category_name}"

# main section day archive
^(?P<cat1>.+)/(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)/*$ = "sections/_section" categories="{router_cat1_category_id}" title="{router_cat1_category_name}"

# main section post
^(?P<cat1>.+)/(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)/(?P<url_title>.+)/*$ = "posts/_detail" categories="{router_cat1_category_id}"

##
## better workflow preview
##
^posts/preview/(?P<entry_id>\d+)/*$ = "posts/_detail"

Other MetaSushi stuff…

ProForm

Be sure to check out my form module ProForm!

ProForm is the first and most powerful drag and drop form manager for ExpressionEngine 2.0. It’s designed to make creation and management of contact forms and other types of public forms easier for developers, content editors, and visitors - everyone who needs to interact with forms in any way.

With ProForm, one line of template code can render simple contact forms, or complex multistep forms all created easily through its drag and drop form builder UI. ProForm also gives you precise control over your forms’ markup through a full template pair - rendering a form is as easy as rendering your site’s content - just the way it should be in ExpressionEngine.

MetaSushi EE Add-ons Newsletter

To stay up to date with the latest ExpressionEngine add-on news from MetaSushi, be sure to subscribe to the MetaSushi EE Add-ons Newsletter today (very low volume).

This entry was created July 17, 2012, 10:24 pm.
This entry was last updated October 31, 2016, 11:23 am.

Disclaimer: Information about ExpressionEngine add-ons is provided as a service to you, the user, and every member of the ExpressionEngine community. devot:ee is not responsible if you hose, mangle, wreck, or otherwise destroy your EE website by installing an add-on that you found out about at this site, regardless of its rating, Favorites status, commercial or free status, or general popularity. Caveat EEmptor!

Returns: devot:ee has a 30-day return policy on all commercial add-ons sold through devot-ee.com. If you need to return an add-on, do not go to the developer or the developer's site, but rather visit our returns page at https://devot-ee.com/returns to initiate your return. If you have questions, email support@devot-ee.com.

1 Review:

T2theC 09.27.13

T2theC
Rating - {addon_rating_average}

This add-on is worth its weight in computer chips! Awesome. It gives you the control needed for site conversions and ANY custom URL structure you can dream up. The support from Isaac has been awesome.

This little beauty has changed the way I guild sites. In combo with Stash, I’ve 20% less code.