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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:07:08+00:00 2026-06-14T07:07:08+00:00

I have converted most of my Apache HTTPd mod_rewrite rules over to nginx’s HttpRewrite

  • 0

I have converted most of my Apache HTTPd mod_rewrite rules over to nginx’s HttpRewrite module (which calls PHP-FPM via FastCGI on every dynamic request). Simple rules which are defined by hard locations work fine:

location = /favicon.ico { rewrite ^(.*)$ /_core/frontend.php?type=ico&file=include__favicon last; }

I am still having trouble with regular expressions, which are parsed in mod_rewrite like this (note that I am accepting trailing slashes within the rules, as well as appending the query string to every request):

mod_rewrite

# File handler
RewriteRule ^([a-z0-9-_,+=]+)\.([a-z]+)$ _core/frontend.php?type=$2&file=$1 [QSA,L]

# Page handler
RewriteRule ^([a-z0-9-_,+=]+)$   _core/frontend.php?route=$1 [QSA,L]
RewriteRule ^([a-z0-9-_,+=]+)\/$ _core/frontend.php?route=$1 [QSA,L]

RewriteRule ^([a-z0-9-_,+=]+)\/([a-z0-9-_,+=]+)$   _core/frontend.php?route=$1/$2 [QSA,L]
RewriteRule ^([a-z0-9-_,+=]+)\/([a-z0-9-_,+=]+)\/$ _core/frontend.php?route=$1/$2 [QSA,L]

RewriteRule ^([a-z0-9-_,+=]+)\/([a-z0-9-_,+=]+)\/([a-z0-9-_,+=]+)$   _core/frontend.php?route=$1/$2/$3 [QSA,L]
RewriteRule ^([a-z0-9-_,+=]+)\/([a-z0-9-_,+=]+)\/([a-z0-9-_,+=]+)\/$ _core/frontend.php?route=$1/$2/$3 [QSA,L]

I have come up with the following server configuration for the site, but I am met with unmatched rules after parsing a request (eg; GET /user/auth):

attempted nginx rewrite

location / {
    # File handler
    rewrite ^([a-z0-9-_,+=]+)\.([a-z]+)?(.*)$                                /_core/frontend.php?type=$2&file=$1&$3 break;

    # Page handler
    rewrite ^([a-z0-9-_,+=]+)(\/*)?(.*)$                                     /_core/frontend.php?route=$1&$2        break;
    rewrite ^([a-z0-9-_,+=]+)\/([a-z0-9-_,+=]+)(\/*)?(.*)$                   /_core/frontend.php?route=$1/$2&$3     break;
    rewrite ^([a-z0-9-_,+=]+)\/([a-z0-9-_,+=]+)\/([a-z0-9-_,+=]+)(\/*)?(.*)$ /_core/frontend.php?route=$1/$2/$3&$4  break;
}

What would you suggest for dealing with my File Handler (which is just filename.ext), and my Page Handler (which is a unique route request with up to 3 properties defined by a forward slash)?

As I haven’t gotten a response from this yet, I am also unsure if this will override my PHP parser which is defined with location ~ \.php {}, which is included before these rewrite rules.

Bonus points if I can solve the parsing issues without the need to use a new rule for each number of route properties.

  • 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-14T07:07:09+00:00Added an answer on June 14, 2026 at 7:07 am

    I ended up writing the following rules:

    File Handler

    location ~ ^/([a-zA-Z0-9-_]*)\.([a-zA-Z0-9]*)$ { include /web/_config/php.conf; rewrite ^/([a-zA-Z0-9-_]*)\.([a-zA-Z0-9]*)$ /_core/frontend.php?type=$2&file=$1 last; }
    

    The file handler grabs the name and extension and writes it into type={ext}&file={name}.

    Page Handler

    location ~ ^/([a-z0-9-_]*)$ { include /web/_config/php.conf; rewrite ^/([a-z0-9-_]*)$ /_core/frontend.php?route=$1 last; }
    location ~ ^/([a-z0-9-_]*)/?([a-z0-9-_]*)$ { include /web/_config/php.conf; rewrite ^/([a-z0-9-_]*)/?([a-z0-9-_]*)$ /_core/frontend.php?route=$1/$2 last; }
    location ~ ^/([a-z0-9-_]*)/?([a-z0-9-_]*)/?([a-z0-9-_]*)$ { include /web/_config/php.conf; rewrite ^/([a-z0-9-_]*)/?([a-z0-9-_]*)/?([a-z0-9-_]*)$ /_core/frontend.php?route=$1/$2/$3 last; }
    

    The page handler (which in this case handles up to 3 “directories”) grabs the string between each separator(/), does a regex-validation and writes it as a query string.

    The main difference between this and my original configuration was that each entry has its own location handler, with the last rule it processes it on the first match, so performance should be slightly better.

    I also discovered that nginx appends query strings by default, so that regex isn’t required, another performance improvement.

    Note that /web/_config/php.conf is simply a FastCGI pass-through configuration, and the one shipped with nginx (usually /etc/nginx/fastcgi.conf) should work fine. Note that if you’re dealing exclusively with PHP, you don’t need to define this in each rule, just prepend them with the include.

    Hope this helps.

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

Sidebar

Related Questions

I have converted an array to object data like this: <?php $myobject->data = (object)Array('zero','one','two');
I have a URL which has been converted into SEO friendly url using .htaccess.But
I have an ArrayList<Double> , the values of which are converted into slices of
i have converted a vb6 ocx to C# com control. this com control is
I have converted an Entity framework project to use POCO objects by removing the
I have converted my Datatable to json string use the following method... public string
I have converted .jpg images into a bitmap thumbnail. What I am trying to
I have converted ILColorPicker to work on XCode4 and Storyboard. My problem is that
Using explode i have converted the string into array , But the array look
I have a 3rd party JAR that I have converted to an OSGI bundle

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.