Topics

Router Maps

Want to give Google a better URL to play with? Tweak your URL with Router Maps.  Though a sample router_maps.php file is not shipped with exponent, you'll find several below.  There is a system router_maps.php file which takes precedence over other router maps, but it currently has no active router maps.  You should run a 'Regenerate Search Index' after updating any router map to update the search hit links.

The optional 'router_maps.php' file is placed in your theme folder.  It simply builds a nested array called $maps.  It consists of three mandatory paramenters:

  • 'controller' - the name of the module being used
  • 'action' - the module action being used
  • 'url_parts' - an array of the parts of the new url used in place of the standard Exponent url.
    • The 'url_parts' item contains the array used to map the revised url to an Exponent standard url (internally) with the key/item name being the standard parameter name and the value being displayed in the revised url.  The sequence and the number of url_parts parameters is vitally important as they must match are parse out identically.  NOTE: if you are creating several maps for the same controller name, etc... you MUST place the array with the greatest number of url_parts parameters first as a similar one with fewer url_parts will be matched before the parser gets to the one with more expected parameters.

Optional parameters would be any parameter normally passed to the controller/action such as 'view', etc...

<?php

$maps = array();

// Find news by the title of the news post.  URL would look like news/my-post-title
$maps[] = array('controller'=>'blog',
     'action'=>'show',
     'url_parts'=>array(
             'controller'=>'blog',
             'title'=>'(.*)'),
);

$maps[] = array('controller'=>'blog',
     'action'=>'showall_by_tags',
     'url_parts'=>array(
             'controller'=>'view-blogs-by-tag',
             'title'=>'(.*)'),
);

$maps[] = array('controller'=>'blog',
     'action'=>'showall_by_author',
     'url_parts'=>array(
             'controller'=>'view-blogs-by-author',
	     'author'=>'(.*)'),
);

$maps[] = array('controller'=>'news',
     'action'=>'show',
     'url_parts'=>array(
             'controller'=>'news',
             'title'=>'(.*)'),
);
?>
<?php

$maps = array();

// Find news by the title of the news post.  URL would look like news/my-post-title
$maps[] = array('controller' => 'news',
                'action'     => 'show',
                'url_parts'  => array(
                    'controller' => 'news',
                    'title'      => '(.*)'
                ),
);

$maps[] = array('controller' => 'blog',
                'action'     => 'show',
                'url_parts'  => array(
                    'controller' => 'blog',
                    'title'      => '(.*)'
                ),
);

$maps[] = array('controller' => 'blog',
                'action'     => 'showall_by_tags',
                'url_parts'  => array(
                    'controller' => 'view-blogs-by-tag',
                    'title'      => '(.*)'
                ),
);

$maps[] = array('controller' => 'blog',
                'action'     => 'showall_by_author',
                'url_parts'  => array(
                    'controller' => 'view-blogs-by-author',
                    'author'     => '(.*)'
                ),
);

$maps[] = array('controller' => 'filedownload',
                'action'     => 'show',
                'url_parts'  => array(
                    'controller' => 'file',
                    'title'      => '(.*)'
                ),
);

$maps[] = array('controller' => 'sermonseries',
                'action'     => 'show',
                'url_parts'  => array(
                    'controller' => 'sermonseries',
                    'title'      => '(.*)',
                    'page'       => '(.*)'
                ),
);

$maps[] = array('controller' => 'sermonseries',
                'action'     => 'show',
                'url_parts'  => array(
                    'controller' => 'sermonseries',
                    'title'      => '(.*)'
                ),
);

$maps[] = array('controller' => 'sermons',
                'action'     => 'show',
                'url_parts'  => array(
                    'controller' => 'sermon',
                    'title'      => '(.*)'
                ),
);
?>
<?php
$maps = array();

// Find help by the title and version.  URL would look like docs/2.0.1/my-help-title
$maps[] = array(
    'controller'=>'help',
    'action'=>'show',
    'version'=>'current',
    'url_parts'=>array(
        'controller'=>'docs',
        'version'=>'(.*)',
        'title'=>'(.*)'
    ),
);


// Find current help by the title. URL would look like docs/my-help-title
$maps[] = array(
    'controller'=>'help',
    'action'=>'show',
    'version'=>'current',
    'url_parts'=>array(
        'controller'=>'docs',
        'title'=>'(.*)'
    ),
);
?>
Loading Help