0

I'm working on a site where the IndexController holds some pages like "about", "contact" and etc. I'd like for either Zend or a .htacess config to redirect /about to /index/about, but without URL re-writing (or at least, have it be transparent to the user).

So it'd perform something like this:

mysite.com/about => mysite/index/about (w/o showing said URI to the user).

4

3 回答 3

2

Using the new Service Manager config:

'controller' => array(
    'classes' => array(
        'index_controller' => 'MyModule\Controller\IndexController',
    ),
),

'router' => array(
'routes' => array(

    'activities_list' => array(
        'type'    => 'Literal',
            'options' => array(
            'route' => '/about', <- The requested URL
            'defaults' => array(
                'controller' => 'index_controller', <- What will process the request
                'action'     => 'about',
            ),
        ),
    ),

), // End of routes
), // End of router
于 2012-06-02T08:09:28.463 回答
1

You don't need anything special to do that, ZF2 is perfectly equipped to handle custom routes. The ZF2 tutorial by Akrabat shows it all well. You'll end up doing something like this in your config:

'Zend\Mvc\Router\RouteStack' => array(
    'parameters' => array(
        'routes' => array(
            'default' => array(
                'type'    => 'Zend\Mvc\Router\Http\Segment',
                'options' => array(
                    'route'    => '/[:controller[/:action]]',
                    'constraints' => array(
                        'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                    ),
                    'defaults' => array(
                        'controller' => 'Application\Controller\IndexController',
                        'action'     => 'index',
                    ),
                ),
            ),
            'about' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        'controller' => 'Application\Controller\IndexController',
                        'action'     => 'about',
                    ),
                ),
            ),
        )
    )
)

Of course you can also automatize these things by extending the ActionController or by writing a Controller Plugin.

于 2012-06-01T18:11:09.297 回答
-1

Try adding this to the .htaccess file in your document root in somewhere appropriate:

RewriteEngine On
RewriteRule ^about(.*)$ /index/about$1 [L]
于 2012-06-01T18:12:16.927 回答