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 3500756
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:46:26+00:00 2026-05-18T12:46:26+00:00

I am trying to create a Zend_Controller_Router_Route_Regex route to process URLs in the following

  • 0

I am trying to create a Zend_Controller_Router_Route_Regex route to process URLs in the following form:

search?q=chicken/page=2 where the first regex subpattern would be chicken and second one would be 2. As for the second part where page=2, I want to make it optional if it is the first page, that is page=1. So another url such as search?q=chicken would also be valid and is equivalent to search?q=chicken/page=1.

Here is my attempt albeit without any success, but to give you a better picture of what I am trying to do.


        $route = new Zend_Controller_Router_Route_Regex(             
            'search\?q=([a-zA-Z0-9]+)(?:/page=(\d+))',
            array( 
                'page'=> '1',
             'module' => 'default', 
             'controller' => 'search', 
             'action' => 'index' ), 
            array( 1 => 'query', 2 => 'page' ),
            'search?=%s/page=%d');
        $router->addRoute('search', $route);

The problem here is I cant compose the correct regex.

Thanks in advance.

EDIT #1

The correct regex, as pointed out by MA4, is 'search\?q=([a-zA-Z0-9]+)(?:/page=(\d+))?'

The real problem is pointed by Darryl. Here is a little bit more info to put things into perspective.

My search text box and button

    <form action="/search" method="get">
            <input type="text" name="q" />
            <input type="submit" value="Search" />
    </form>

Every time I press the search button, I get the search?q=[text] request. How do I force it to go through the regex match route?

Here is what i want to do, however the code does not work

    if($this->getRequest()->getParam('query')){
        // redirect success
    } else {
        $url = "search?q=" . $this->_getParam('q');            
        $this->_redirect(route('search'), array('code' => 301 ));
    }
  • 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-05-18T12:46:26+00:00Added an answer on May 18, 2026 at 12:46 pm

    /search?q=chicken/page=2 is not parsable by Zend Frameworks’ router. The router will only see /search.

    The router relies on the Path Info provided by the server and anything after the ? is the query string.

    You would need to use a path such as this:

    /search/[word]        (default page 1)
    /search/[word]/[page] 
    

    In which case your regex would become much simpler.

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

Sidebar

Related Questions

I'm trying to create a custom form element which extends Zend_Form_Element_Text with a validator
I am new to zend. I am trying to create login form using zend
Hello there i'm trying to create a form with Zend_Form that will enable my
I am trying to create my first unit test. I use Zend Studio, and
I have been trying to create a custom form with Zend_Form and Decorators, the
I'm trying to create a contact form. However at the top of the form
I'm trying to create a form using Zend_Form (Zend_Framework component). The users should be
I'm trying to implement canonical URLs and combine it with custom route-classes. The URL-scheme
I am trying to create an API centric webservice using Zend framework. I would
I'm trying to create a Zend Framework project using PHP 5.3.2 and Zend Framework

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.