Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:44:14+00:00 2026-06-11T18:44:14+00:00

With the Zend Framework, I am trying to build a URL to SEO friendly

  • 0

With the Zend Framework, I am trying to build a URL to SEO friendly URL

http://ww.website.com/public/index/categories/category/2
should be mapped by http://ww.website.com/public/index/categories/category.html

http://ww.website.com/public/index/products/category/2/subcategory/2
should be mapped by http://ww.website.com/public/index/products/product.html

In my Bootstrap file I have tried this

protected function _initRoutes()
{ 
    $frontController = Zend_Controller_Front::getInstance ();
    $router = $frontController->getRouter ();
    $route = new Zend_Controller_Router_Route_Regex(
        'index/categories/category/(\d*)/',
        array('module' => 'default','controller' => 'index','action' => 'categories'), 
        array(1 => 'category'),
        'index/categories/%d-%s.html');

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

Now my question is how to rewrite this URL? I am also retrieving the products or categories based on the IDs in the URL using:

$id = $this->_getParam('category', 0 ); 

Anyone could help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:44:15+00:00Added an answer on June 11, 2026 at 6:44 pm

    I think you do not need Regex route for what you need.
    If you want for example this url:
    http://mysite.com/category/cars.html to go to http://mysite.com/categories/category/id/2 is enough to use Zend_Controller_Router_Route

    Now is only one problem Zend Router will not know id of you category to map, for this you need to store your custom routes to database or a file; Each custom route will contain url that map and required parameters (controller name, action name, id of category).

    After we have that we can build a function that register a custom route to bootstrap file, or in some plugin like this one:

    public function setRoute($params){
        $router = Zend_Controller_Front::getInstance()->getRouter();
        $params = array(
            'controller' => $params['controller'],
            'action'     => $params['action'],
            'id'         => $params['id']
            );
        $route = new Zend_Controller_Router_Route($params['url'], $params);
        $router->addRoute($params['url'], $route);
    }
    

    Now let suppose that $params['url'] has value: http://mysite.com/category/cars.html when is requested from browser that url ZF will match our custom route and forward request to specified controller in $params['controller'], and call specified action in $params['action'] and will set as parameter named id value from $params['id'] wich can be retrieved from controller with $id = $this->_getParam('id',0);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a Connect app using PHP and the Zend Framework.
With the Zend Framework, I am trying to build routes for a REST api
I am trying to migrate to zend framework. Should each webpage be a Controller
I have a website running using Zend Framework and am trying to setup Zend
I am trying to build a social network using Zend Framework. However, recently I
I'm trying out the zend framework classes for the first time. I am interested
I'm trying to create a Zend Framework project using PHP 5.3.2 and Zend Framework
I'm trying to set up my zend framework application on this host but I'm
I'm trying to get started with Zend Framework , followed the quickstart project and
I am trying to use the new Eventmanager of the Zend Framework 2. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.