Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

URL Rewriting with Zend Router
 
Fittster
Jr. Member
 
Total Posts:  6
Joined:  2008-09-22
 

Hi,

I’ve been moving my site over to use magento and the Zend Framework is something new to me, but I’ve managed to get a hold of adding new modules, templates, blocks etc etc however there’s just one bit left before I can get it live, and that’s URL rewriting.

After lots of googling it seems you have to use the Zend Framework’s Controller Router to do this.

I found this topic - http://www.electrictoolbox.com/zend-framework-controller-router-example/ but everything I try doesn’t work.

So… I can get to a URL like this for example:

http://www.mydomain.com/foo/bar/view/id/1

This shows all the info that it’s supposed to, so far so good!

However I don’t like that URL, I’d prefer it to be:

http://www.mydomain.com/foo/1

This is what I put in my index.php file (which I assume is the bootstrap?):

$ctrl = Zend_Controller_Front::getInstance();
$router = $ctrl->getRouter();

$router->addRoute(
‘foo/:id’,
new Zend_Controller_Router_Route(’foo’, array(’controller’ => ‘bar’, ‘action’ => ‘view’))
);

Here is my full index.php file so you can see where I’ve placed this:

<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage
* @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

if (version_compare(phpversion(), ‘5.2.0’, ‘<’)===true) {
echo ‘<div style="font:12px/1.35em arial, helvetica, sans-serif;"><div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;"><h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer. <a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a> Magento using PHP-CGI as a work-around.</p></div>’;
exit;
}

$mageFilename = ‘app/Mage.php’;

if (!file_exists($mageFilename)) {
if (is_dir(’downloader’)) {
header("Location: downloader");
} else {
echo $mageFilename.” was not found”;
}
exit;
}

require_once $mageFilename;

#Varien_Profiler::enable();

#Mage::setIsDeveloperMode(true);

#ini_set(’display_errors’, 1);

$ctrl = Zend_Controller_Front::getInstance();
$router = $ctrl->getRouter();

$router->addRoute(
‘foo/:id’,
new Zend_Controller_Router_Route(’foo’, array(’controller’ => ‘bar’, ‘action’ => ‘view’))
);

umask(0);
Mage::run();

Am I anywhere near on the right track? All I want it to point create custom modules/blocks etc and then specify URL rewrites for them! Sounds so easy doesn’t it?!

Any help is greatly appreciated.

Fitty

 
Magento Community Magento Community
Magento Community
Magento Community
 
retif
Sr. Member
 
Total Posts:  171
Joined:  2008-08-16
Odessa, Ukraine
 

magento does not uses zend routers, there are own implementation..see
../Core/Controller/Front.php
../Core/Controller/Router/Standard.php

u can create own routers in custom module, and assing them into magento using xml notation..search for “router” in *.xml

 
Magento Community Magento Community
Magento Community
Magento Community
 
Fittster
Jr. Member
 
Total Posts:  6
Joined:  2008-09-22
 

I’m totally lost! No idea what to do confused

 
Magento Community Magento Community
Magento Community
Magento Community
 
nadshez
Member
 
Avatar
Total Posts:  48
Joined:  2008-04-16
 

So did you ever find a solution? Cause I am stuck in a similar situation myself & would love to know the solution. Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top