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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:21:24+00:00 2026-06-07T15:21:24+00:00

I need a rule in Apache that redirects not-found CSS files to another location

  • 0

I need a rule in Apache that redirects not-found CSS files to another location based on their names in another folder. Like this:

  • Request: localhost/css/nonexistent.css
  • Response: localhost/css/g/nonexistent.css

If the CSS exists, just serve it like normal:

  • Request: localhost/css/existent.css
  • Response: localhost/css/existent.css

My project is on CakePHP which comes with the following rules by default:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L] 

I mention it because whatever the new rule is, it should not break Cake’s rules.

Thanks for the help.

Edit: Forgot to mention that the css/g/ file is an alias for a script (inside the Cake MVC stack) that generates the new css file and echoes it. Answers so far seem to do the redirection fine, but then it doesn’t find the css/g/file.css either because it really doesn’t exist.

  • 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-07T15:21:25+00:00Added an answer on June 7, 2026 at 3:21 pm

    You can try first checking if the /css/g/ css file exists:

    # Make sure it doesn't exist
    RewriteCond %{REQUEST_FILENAME} !-f
    # Make sure this is a request for a css file:
    RewriteCond %{REQUEST_URI} ^/css/(.*)\.css$
    # See if the /g/ version exists
    RewriteCond %{DOCUMENT_ROOT}/css/g/%1.css -f
    # rewrite if all conditions satisfied
    RewriteRule ^css/(.*)$ /css/g/$1 [L]
    

    The %1 in the 3rd condition backreferences the filename (sans .css extension) matched in the previous RewriteCond.


    EDIT:

    If the file css file is actually generated, then skip the checking of /g/ version and just pass it to the controller:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} ^/css/(.*)\.css$
    RewriteRule ^css/(.*)$ index.php/css/g/$1 [L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm struggling with a css selector. I need a css rule that returns all
I need to build a rule-based system that can be run and developed in
Need a makefile dependency rule that can handle missing files gives some pointers on
I need a rewrite rule that will take a folder (dynamic) and rewrite it
I need to add a rule in the firewall so that my self-hosted http
I have the following rewrite rule that I need to alter in order to
One rule that I need is that if the last vowel (aeiou) of a
I need a rule for http://example.com/post/view/id/1 url that will be displayed like this http://example.com/post/post_title
I need to write a rule that blocks a mysql query.. like RewriteCond %{QUERY_STRING}
Ok I am need of a rule that can report true on only /

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.