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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:18:40+00:00 2026-06-08T02:18:40+00:00

Hi – I’ve been struggling with this for days. It seems simple but I

  • 0

Hi – I’ve been struggling with this for days. It seems simple but I just can’t get it done.

I have a site developed in CakePHP. There’s a script that responds to /css/profiles/g/whatever.css (“whatever” being whatever, it is actually a parameter that gets passed to the action), it echoes a generated CSS and saves it to /css/profiles/whatever.css.

I have a rule in Apache that takes requests to /css/profiles/whatever.css and, if it doesn’t exist, rewrites the request to /css/profiles/g/whatever.css without redirecting, so the client never notices it was responded by a script and that the file didn’t exist.

This is what I have in Apache:

# Profile CSS rules
RewriteCond %{REQUEST_URI} ^/css/profiles/
RewriteCond %{REQUEST_URI} !/css/profiles/g/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^css/profiles/(.*)$ /css/profiles/g/$1 [L]

# CakePHP's default rules
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

Now I’m moving the site to a server with Nginx, and so far I’ve got this:

# Profile CSS rules
location ~ ^/css/profiles/(?!g/)(.*)$ {
    if (!-f $request_filename) {
      rewrite ^/css/profiles/(.*)$ /css/profiles/g/$1 last;
      break;
    }

 }

# CakePHP's default rules
location / {

    try_files $uri $uri/ /index.php?$uri&$args;
}

The conditions seem to be working, because if I go to /css/profiles/whatever.css and print out PHP’s $_SERVER variable it gives me

[QUERY_STRING] => /css/profiles/g/whatever.css&

Notice the &. It means it got to the try_files part and added the $uri to the query string, and it has the correct $uri.

But…

[REQUEST_URI] => /css/profiles/whatever.css

That’s the glitch. It seems it’s not really changing the $request_uri which is what CakePHP needs to control what controller attends what.

Update: The REQUEST_URI value is right… the issue here is that Cake looks for the value of different server variables to decide which controller will respond. In this order: $_SERVER['PATH_INFO'], $_SERVER['REQUEST_URI'], a combination of $_SERVER['PHP_SELF'] and $_SERVER['SCRIPT_NAME'] and finally $_SERVER['HTTP_X_REWRITE_URL']. That’s why it’s failing.

Any help will be appreciated.

Thanks.

Note: I posted this question on Serverfult yesterday because I think it fits better there but didn’t get an answer, that’s why I’m posting it here too.

  • 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-08T02:18:41+00:00Added an answer on June 8, 2026 at 2:18 am

    So I finally got it working:

    location ~ ^/css/profiles/(?!g/)(.*)$ {
      set $new_uri /css/profiles/g/$1;
      if (!-f $request_filename) {
        rewrite ^/css/profiles/(.*)$ /css/profiles/g/$1 last;
      }
    }
    

    …and at the end:

    location ~ \.php$ {
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi_params;
    
      ... some other stuff were here related to fastcgi
      fastcgi_param PATH_INFO $new_uri; # <--- I added this
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have been unable to fix a problem with Java Unicode and encoding. The

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.