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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:30:20+00:00 2026-05-23T05:30:20+00:00

This might seem a bit basic and something that’s been asked quite a lot

  • 0

This might seem a bit basic and something that’s been asked quite a lot around here, but I have a small .htaccess problem (mod_rewrite).

I’m working on a MVC framework for PHP (like everybody else…) and all traffic goes through index.php which then routes to the required controller and method. All that goes well. The structure is roughly something like this:

  • application
    1. controllers
    2. models
    3. views
  • cache
  • framework
  • public
    1. assets
    2. img
    3. css
    4. js
  • index.php
  • .htaccess

For an URL like myapp.com/css/ I need o load the CSS controller, index function. But for URLs like myapp.com/css/style.css I need to fetch the file from the public/css/directory

I’d hate writing /public/ for each file I want to include, so basically I need to redirect all traffic to /public/ if it’s an actual file and keep the normal rewriting rule for all other URLs. I’m planning to use this in production and it would be much easier to let frontend developers do their stuff the way they normally do it and then just copy paste stuff into place instread of going through CSS to modify paths and such.

I came up with this:

RewriteEngine on

RewriteRule ^(img|css|js|assets)/(.*).([a-z]{3})$ public/$1/$2 [L,NC]

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

But it has some obvious flaws. I don’t mind having to set directories in the first regex, but checking that the path is a file the way I do seems rather unreliable. Using RewriteCond to check that it’s a file didn’t work for some reason and I think this method can fail for URLs like myapp.com/img/this-is-actually-an-article.aaa Of course, extensiuons can also be longer than 3 characters and I need to check that that’s safe as well.

What’s the best way to go about this? How do you guys ussually do it? Or is this a wrong approach from the very begining?

  • 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-23T05:30:21+00:00Added an answer on May 23, 2026 at 5:30 am

    The -f isn’t working because the requested file is /css/style.css whereas the file on disk is /public/css/style.css.

    I see no problem with declaring some predefined namespaces that you can’t use in your application (like img, css, js, assets).

    Eventually I think you will move to a situation where plugins for your framework can no longer decide where their resources are, the framework should decide it for them and possibly even load it for them. This resolves all your current issues as no plugin code will ever need to know anything about URLs. Regardless of your rewriting strategy I think this is something to aspire to.

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

Sidebar

Related Questions

This might seem ridiculously simple, but I've been getting all kinds of error depending
I know this might have been asked a thousand times before, but I can't
This might seem a bit like a do-my-homework-for-me question (and it is), but I
This might seem a bit awkward but I want to start a console program
This might seem daft for which I'm sorry, I've been writing a bit some
This question might seem a bit bizarre, but... I run a mafia style game
This might seem like a trivial question, but I'm a bit muddled in my
This might seem like a stupid question I admit. But I'm in a small
This might seem obvious but I've had this error when trying to use LINQ
This might seem like a ridiculous question since I'm quite inexperienced in .NET. Is

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.