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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:53:38+00:00 2026-05-27T19:53:38+00:00

I have a site with two RESTful URL schemes: foo.com/model/id and foo.com/model/id/action The actual

  • 0

I have a site with two RESTful URL schemes:

foo.com/model/id and
foo.com/model/id/action

The actual pages served by these URLs are in the form of

$model.php?id=$id and
$model_$action.php?id=$id respectively.

I have a single regular expression that will match both cases ^(\w+)s/([A-z0-9]+)(?:/(\w+))?/?$ and I’d like to use a single Nginx rule to rewrite for both types of URLs, but I’m not sure how to do this. In pseudocode I imagine the rule would look something like this

rewrite ^(\w+)s/([A-z0-9]+)(?:/(\w+))?/?$ /(($3) ? $1_$3.php?$id=$2 : $1.php?$id=2)

This isn’t valid syntax (so far as I know), but can something like this be done in Nginx?

  • 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-27T19:53:39+00:00Added an answer on May 27, 2026 at 7:53 pm

    Rewrite the possible urls in turn starting with the longest to the shortest to that overlapping matching strings, “/model/id” in this case, would be matched in the longer url string first.

    location / {
        # For "/model/id/action" to "$model_$action.php?id=$id"
        rewrite ^/(.+)/(.+)/(.+)(/?)$ $1_$3.php?id=$2 last;
    
        # For "/model/id" to "$model.php?id=$id"
        rewrite ^/(.+)/(.+)(/?)$ $1.php?id=$2 last;
    }
    location ~ .+\.php$ {
        # Handle PHP
    }
    

    The “(/?)” is just in case the urls sometimes come with an ending slash. If they never do, it can be removed. In this case, it will probably be best to specifically always add a closing slash and have “(/?)” as “/”.

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

Sidebar

Related Questions

I have two similar wordpress websites. http://site.com/ and http://site.com/en/ When I try to load
I have two pages, NonMember.aspx and Member.aspx. If a user comes to the site,
i have a site like twitter.com on server one and on server two i
I need to have two separate pages on the site I'm planning to build
I have a site which consists of mydomain.com (and URLs derived from it such
I have a site whose URLs look like http://www.example.com/NY-2010/ http://www.example.com/NY-2010/location/ http://www.example.com/NY-2010/something-else/ http://www.example.com/Washington-2009/ http://www.example.com/Washington-2009/location/ http://www.example.com/Washington-2009/something-else/
I have a simple web site with two pages. One displays a list of
I have a site that redirects from www.domain.com to www.domain.com/sub I have two domains
I have a site that uses AJAX to navigate. I have two pages that
I have a web site with two routes. Basically the user can do one

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.