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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:25:52+00:00 2026-05-13T07:25:52+00:00

I am working with Urls in the following format: controller/action where the slash is

  • 0

I am working with Urls in the following format: “controller/action” where the slash is required.

I need to create a PCRE regex to match the controller and action names unless the controller name has the value of “home.” For example:

  • “member/update” should produce “member”, “update”
  • “admin/index” should produce “admin”, “index”
  • “home/index” should produce <nomatch>

I’ve been playing around with look ahead, behind, and around and I have parts of it working but no totally correct solution. Any help appreciated.

** EDIT
Here’s a little more background. I want to set up Zend routing so that

  • an url with just one part ‘/foo’ dispatches to HomeController, i.e. ‘/home/foo’
  • any url with two parts ‘/controller/action’ dispatches to that controller: e.g., ‘/member/update’ dispatches to MemberController, ‘/member/update’;   ‘/home/index’ dispatches to HomeController, etc.

Right now I have routes set up as:

$router->addRoute('homeRoute', 
    new Zend_Controller_Router_Route(
        ':action',
        array('controller' => 'home', 'action' => 'index')
    )
);
$router->addRoute('memberRoute', 
    new Zend_Controller_Router_Route(
        'member/:action',
        array('controller' => 'member', 'action' => 'index')
    )
);
// and so on, a route for each non-Home controller: adminRoute, etc

This is working the way I want but it’s ugly and a maintenance problem. I’m want to replace all of the routes ‘memberRoute’, ‘adminRoute’, etc, with a single Regex route:

$router->addRoute('siteRoute',
    new Zend_Controller_Router_Route_Regex(
        '????/:action',
        array('action' => 'index'),
        array(?? => 'controller')
    )
);

I have been running my regex experiments with a little php script like:

<?php
    preg_match('/????/', 'home/index', $output);
    echo '0=>'.$output[0].';';
    echo '1=>'.$output[1].';';
?>
  • 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-13T07:25:53+00:00Added an answer on May 13, 2026 at 7:25 am

    (?:home.*)|([^/]*)(?:/(.*))?

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

Sidebar

Related Questions

I have the following urls that need mapping to two different servlets. Can anyone
I've got the following regex that was working perfectly until a new situation arose
I am working on existing project. I have following two URLs http://example.dev/en/course/myUserName/myCourseName/150/myChapterName/1016/page/1/?hcid=147 http://example.dev/en/course/myUserName/myCourseName/150/myChapterName/1016/page/2/?hcid=147 2nd
I need apache to call file.php when either of the following urls are called:
Can a single regex be used to valdate urls and match all the parts,
I'm trying to get mod_rewrite working with the following URLs: /events.php?view=details&id=$var /events.php?view=edit&id=$var Obviously my
I am working with following regex in C# Regex find = new Regex([,\]url(?<Url>[^\\]+)\\u0026); and
Currently, one of my urls is not working properly because I can't match it.
I'm having little trouble creating a script working with URLs. I'm using urllib.urlopen() to
I'm working on building the URLs for my REST API before I begin writing

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.