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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:33:31+00:00 2026-05-16T04:33:31+00:00

I’m having some difficulties with mod_rewrite. My directory structure (part of it) is: index.php

  • 0

I’m having some difficulties with mod_rewrite. My directory structure (part of it) is:

index.php
.htaccess
app
  controllers
  models
  views
  ...
  public
    javascripts
    stylesheets
    foo
      bar

So, as you can see, all static files are in app/public. That’s the reason I would like to route requests like:

http://www.example.com/images/logo.png => app/public/images/logo.png  
http://www.example.com/javascripts/app.js => app/public/javascripts/app.js  
http://www.example.com/uploads/blog/something => app/public/uploads/blog/something

If that file doesn’t exist, then it should route to index.php, like:

http://www.example.com/news/show/42 => index.php 
(Because file app/public/news doens't exist)

So, this is my current .htaccess, but I think it can be done in more elegant way.

RewriteEngine on
RewriteRule (png|jpg|gif|bmp|ico)$ app/public/images/$1/$2.$3 [L]
RewriteRule ([^/.]+).js$ app/public/javascripts/$1.js [L]
RewriteRule ([^/.]+).css$ app/public/stylesheets/$1.css [L]
RewriteRule ^(.*)$   index.php    [NC,L,QSA]

Also, problem with this one is, it only handles images, javascripts and stylesheets, but not all other files.

I know there is:

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d

But, I don’t know how to route them with prefix “app/public/”? I tried:

RewriteCond app/public/%{SCRIPT_FILENAME} !-f
RewriteCond app/public/%{SCRIPT_FILENAME} !-d

But it doesn’t work! I also tried using RewriteBase, but it didn’t work out.

EDIT:
I’m using mod_expires, and I’d really like to automate requests like:

http://www.example.com/images/logo.42.png => app/public/images/logo.png  
http://www.example.com/javascripts/app.42.js => app/public/javascripts/app.js  

So, as you can see, I would like to have optional number between filename and extension, and that number should be ignored (it is only used for future expires).

Previously, I found:

RewriteRule ^(.*)\.(\d+)(_m_\d+)?\.([^\.]+)$ $1.$4 [QSA]  

But I don’t really understand how it works and does it always work in my example (multiple extensions maybe)?

Thanks!

  • 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-16T04:33:32+00:00Added an answer on May 16, 2026 at 4:33 am

    Try this instead:

    /.htaccess

    RewriteEngine on
    RewriteRule    ^$ app/public/    [L]
    RewriteRule    (.*) app/public/$1 [L]
    

    /app/.htaccess

    RewriteEngine on
    RewriteRule    ^$ public/    [L]
    RewriteRule    (.*) public/$1 [L]
    

    /app/public/.htaccess

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

    Finally, create an index.php in your /app/public/ and put a dispatcher here:

    <pre>
    <?php
    
    function dispatch($action, $request) {
    
        echo 'action: ' . $action;
        echo "\nparameters: " ;
        print_r($request);
    }
    
    $fragments = explode('/', $_GET['url']);
    dispatch($fragments[0], array_slice($fragments, 1));
    
    ?>
    </pre>
    

    Now say try accessing:

    # these will go through php
    /controller/action
    /post/create
    /post/delete/1
    
    # these are static files
    /stylesheets/
    /foo/bar/myfile.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.