1

I'm writing a Zend Framework application and its not a big deal but I can't figure out (even after googling) how to remove the /index/ from the url

So I currently have this

http://myapplication.local/index/home

When I really want

http://myapplication.local/home

I understand it may be possible to do this via the .htaccess?

1
  • 1
    I belive you can use a "router" to do this. Unfortunately my internet connection is kinda broken so I can't check that url, but I'm pretty confident it can do the trick for you ;) Commented Jan 19, 2012 at 20:14

2 Answers 2

4

The issue occurs because Zend by default uses controller/action urls (which is a default route). Because your root controller is IndexController and the action is IndexController::homeAction it is accessed via index/home.

The easiest way to do what you want is adding routes to the application.ini as follows:

resources.router.routes.home_route_or_any_name.route = "home"
resources.router.routes.home_route_or_any_name.defaults.module = "default"
resources.router.routes.home_route_or_any_name.defaults.controller = "index"
resources.router.routes.home_route_or_any_name.defaults.action = "home"

You can change home_route_or_any_name to anything you want. You can also add many routes definitions to fit your needs.

For more information refer to Zend Framework Documentation

Sign up to request clarification or add additional context in comments.

Comments

0

You can try this in bootstrap.php

/**
 * Setup Routig. 
 * Now all calls are send to indexController like
 * URL/ACTION-1
 * URL/ACTION-2
 *
 * @return void
 **/
protected function _initRouters()
{
    $router = Zend_Controller_Front::getInstance()->getRouter();

    $route = new Zend_Controller_Router_Route(
        ':action/*',
        array(
            'controller' => 'index',
            'action' => 'index'
        )
    );        

    $router->addRoute('default', $route);
}

I will remove index from all the action generated from indexController.
OR
in application.ini

routes.index.type = "Zend_Controller_Router_Route"
routes.index.route = "/"
routes.index.defaults.module = "default"
routes.index.defaults.controller = "index"
routes.index.defaults.action = "index"

For molre detail on routing you can read here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.