views:

90

answers:

2

An application I'm working with has the page structure setup such so that when you create a new page and view it, the URI is:

http://site.com/page/open/title/Contact Us

A client has requested that we need shortened urls, so for example the prior URI should be something like http://site.com/contact-us/

The reason why there's a generic page controller is because these pages have editable content regions in an admin area and it's much easier controlling them with this type of structure.

In regards to the request of shortening them, how should I go about this? Should I, for example, create controllers for each of the 20 pages and somehow reroute them, or setup some method in my initial page controller as a shortcut to open/title/ such as page/name/Contact Us? I would think that relying on custom rewrite rules is a dirty solution and I shouldn't need to use any, perhaps I'm wrong?

By the way, some of these pages will also have custom dynamic content such as forms, so they're not all purely html/static. Any advice is appreciated.

A: 

You can approach this with zend routing or mod_rewrite. My logic would be

- If URL exists, route to the matched one
- If URL does not exist, check if space is present 
        - Replace space with '-' (or other delimiter) then do the checking again. 
        - If no space is present, display a 404 or redirect to front page.
Jay Zeng
can you demonstrate how you'd do this with Zend Route?
meder
+2  A: 

you must create "slug" for page title. it'll be like 'contact-us' and save it

then use standart router functionality

routes.showarticles.type = "Zend_Controller_Router_Route_Regex"
routes.showarticles.route = "articles(?:/([a-zA-Z\-]+))?"
routes.showarticles.reverse = "articles/%s"
routes.showarticles.defaults.controller = "posts"
routes.showarticles.defaults.action = "show-articles"
routes.showarticles.map.1 = "slug"
routes.showarticles.defaults.slug = slug

something like this

or u can do like stackoverflow including page_id in url and optional slug part like

http://zagon.org/articles/ku-ka-re-ku/56/edet-kujvashev-na-velosipede-7

http://zagon.org/articles/ku-ka-re-ku/56

EDIT

protected function _initRoutes()
{
    if ($this->hasOption('routes')) {
        $this->bootstrap('frontController');
        $frontController = $this->getResource('frontController');
        /* @var $router Zend_Controller_Router_Rewrite */
        $router = $frontController->getRouter();
        $router->addConfig(new Zend_Config($this->getOption('routes')));
    }
}
SM
Is there a difference between your first code snippet, which I believe goes in application.ini, and manually adding a init method for routers in Bootstrap by catching the Front Controller and adding it? Are they two alternative ways?
meder
in ZF you can do one thing by many ways. i'm using ini files fo config only and process them ad Bootstrap.php
SM
add an example. i know that ZF has App_Resouce_Routes - but i don't use it, because of my modules architecture.
SM