Chapter 5. Zend_Controller_RewriteRouter

Table of Contents

5.1. Introduction
5.2. Using a router
5.3. Basic Routes
5.4. Variable defaults
5.5. Variable requirements
5.6. Base URL and subdirectories
5.7. Default routes

5.1. Introduction

Zend_Controller_RewriteRouter is a new version of the framework router. Routing is the process of taking a URI endpoint and decomposing it to determine which controller and action of that controller, should receive the request. This definition of controller, action and optional parameters is packaged into a value object called Zend_Controller_Dispatcher_Token which is then processed by Zend_Controller_Dispatcher. Routing occurs only once: when the request is initially received and before the first controller is dispatched.

Zend_Controller_RewriteRouter is designed to allow for mod_rewrite like functionality using pure php structures. It is very loosely based on Ruby on Rails routing and does not require any prior knowledge of webserver URL rewriting. It is designed to work with a single mod_rewrite rule (one of):

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1