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

  • Home
  • SEARCH
  • 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 598065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:20:55+00:00 2026-05-13T16:20:55+00:00

I have my server’s apache configured to redirect every request into index.php, so that

  • 0

I have my server’s apache configured to redirect every request into index.php, so that I can use urls like :

http://www.website.com/about/us

Now I need to parse the url in order to determine if each route exists and what to expect from it, so I can set a database table to save the routes and so my clients can edit their routes as they like them to be. Thing is, I’m not able to do the parsing so far.

Here’s my code :

$uri = 'about/us';
$regex = '(page(/<action>))';
if ( ! preg_match($regex, $uri, $matches)) {
    echo 'the route doesn\'t match';
    exit();
}

It always shows up that echo message. What am I doing wrong?

edit :

The reason why I need regex is as follows. Imagine I have a url segment like :

/user/yoda

The regex here would be usefull to parse the first argument as an action or page, and the second as a key that will only allow a certain set of chars, like if I want to expect, in this case, the second paramenter only to match “_-azAZ09”, something like this. In other words, the set of regex expressions would me compared to the uri in order to determine if any of them matches the uri, and determine the action to take from that on. Using the explode function would make me evaluate the uri segments later in the code, wich I’d like to avoid. If there’s no match to the uri, immediatelly forward the page to a 404 one and break the operation. Don’t know if I made myself clear ..

  • 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-13T16:20:55+00:00Added an answer on May 13, 2026 at 4:20 pm

    Instead of using regular expressions, why not simply split the incoming URI?

    $uri = 'about/us';
    list($page, $action) = explode('/', $uri);
    

    If you need more than two, simply remove the list:

    $pagePath = explode('/', $uri);
    

    But, if you insist on using regular expressions, this will do:

    $regex = '#(?P<page>.*)/(?P<action>.*)#';
    

    However, it offers you nothing special except that $matches will now contain $matches['page'] and $matches['action'] – but if you really need it, youcan use list() as shown above.


    Using the explode function would make
    me evaluate the uri segments later in
    the code, wich I’d like to avoid

    Instead of making sure the page is valid by it’s character set, why not compile a list of valid pages lookup table and just use php’s in_array which is much faster than a regular expression? Extracting the URL segments into an array will allow you to have multi-dimension arrays validated in no time.

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

Sidebar

Ask A Question

Stats

  • Questions 318k
  • Answers 318k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The repository has example code. If you want to use… May 13, 2026 at 11:51 pm
  • Editorial Team
    Editorial Team added an answer The text in a post is actually an anchor <a>… May 13, 2026 at 11:51 pm
  • Editorial Team
    Editorial Team added an answer Could be true but depends over your design. An Application… May 13, 2026 at 11:50 pm

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a problem with time My server is in the USA and I'm
I have used SO_REUSEADDR to have my server which got terminated to restart without
in visual studio i have my code point to a sql server mdf file
I have my application working fully on my development machine and storing data all

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.