I have been using this since the beginning of thte framework for the simplest of projects (the ones that only require one controller and no modules and where the extra 'index' in the url only hurts the eyes):

- This is a snippet from an INI config file:

[main]
; Settings for routing engine
routes.all.route = ":action/*"
routes.all.defaults.controller = index
routes.all.defaults.action = index

- I use this in my bootstrap file to use it:

/* Set up config object */
$config = new Zend_Config_Ini('../app/config/config.ini', 'main');

/* Create a router */
$router = new Zend_Controller_Router_Rewrite();
$router->addConfig($config, 'routes');

/* Create a Zend_Controller_Front object and add route */
$front = Zend_Controller_Front::getInstance();
$front->setRouter($router);

It's used with the default rewrite rules in the docs.

Hope this helps!
Kind regards,


Ramon de la Fuente

dbowen wrote:
I realized a much simpler solution to this. Just create a 'index' folder in
your web root. Problem solved!

It requires the rewrite rules suggested in the docs though. Other rewrite
rules might not work.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Of course the server response you "should" want from /index is a "page not
found" but depending on your server configuration you'll either get a
directory listing or permission denied. To me this doesn't matter much as I
just want to prevent duplicate content in the search engines.

Hope that helps.


Mon Zafra wrote:
I made a custom router for this purpose(see attachment). It's identical to
Zend_Controller_Router_Route_Module with slightly modified match() and
assemble() methods.

The default Module router basically explodes the path, walks through it,
takes each part then assigns them to the module (only if the first part is
a
valid module, otherwise it is set to default), controller and action
respectively then the rest is set as params. I modified it to also check
if
the controller is valid by making a test request and calling
$dispatcher->isDispatchable() on it. I don't know if that's the proper way
to do it, but it works good enough for my needs.

For the action part, since actions are called via a magic function (I
think)
there's no way to test if an action is defined without catching
exceptions.
So I just made an assumption that the requested action is the default
action
if the remaining parts (after assigning the module and controller) has an
even number of elements. Otherwise, the next part is used as the action
and
the rest as param=>value pairs. So this router won't work as expected if
you
have a param with no matching value.

On Tue, Oct 21, 2008 at 7:54 AM, t-mow <[EMAIL PROTECTED]> wrote:

Hi guys,

my solution for this is adding this route in bootstrap:
$front->getRouter()->addRoute('indexFix', new
Zend_Controller_Router_Route(':action',
array('module'=>'default','controller'=>'index','action'=>'')));

The only point thats not that cool, is that you cannot call any other
controller just by it's controller name - you'll have to specify an
action
to access these. For example /users/search will work, just "/users"
won't,
because it will call IndexController::usersAction ;)


David Mintz-3 wrote:
On Sun, Oct 19, 2008 at 9:31 AM, till <[EMAIL PROTECTED]> wrote:

On Sun, Oct 19, 2008 at 7:25 AM, TimTowdi <[EMAIL PROTECTED]> wrote:
I want all actions for my IndexController to work using only the
action
name,
and actually redirecting if the index controller name is used.  So:
       http://example.com/index/sitemap/
Would actually issue a redirect to:
       http://example.com/sitemap/


However, I will have other controllers, and I want them to use both
controller and action, so for the indexAction of AdminController:
       http://example.com/admin/
And for the loginAction of AdminController:
       http://example.com/admin/login/

How would this best be accomplished?
Don't hold me responsible for typos, but ...

$router->addRoute('sitemap',
 new Zend_Controller_Router_Route('/sitemap',
   array('controller' => 'index', 'action' => 'sitemap', 'module' =>
'default')));

That should go in your bootstrap, whereever you setup your routes.

I think he wants to know one routing recipe whereby all the actions in
his
index controller can be accessed as example.org/action instead of
example.org/index/action. I have wondered the same thing but was afraid
to
ask :-) Though I could image an intelligent 404 handler but that
doesn't
seem the most efficient solution.



--
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness


--
View this message in context:
http://www.nabble.com/Routing-so-that-%27index%27-never-shows-up-in-the-url--tp20053411p20081102.html
Sent from the Zend Framework mailing list archive at Nabble.com.




Reply via email to