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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:18:15+00:00 2026-05-15T16:18:15+00:00

Hey, I’ve been reading StackOverflow.com for a long time but decided to sign up

  • 0

Hey, I’ve been reading StackOverflow.com for a long time but decided to sign up to ask a question. I’m writing my own lightweight MVC framework that routes page requests in index.php.

Page requests look like /controller/action/arg1/arg2/arg3, and they should be rewritten to index.php?route=[request]. So, a [request] like site.com/user/profile/123 should be rewritten to index.php?route=user/profile/123

However, files aren’t meant to rewrite to index.php. Assets such as images and stylesheets are in the /app/webroot/ folder, and don’t need PHP to be executed. So, the mod_rewrite engine should rewrite any filerequests to /app/webroot/, and serve the configured 404 ErrorDocument when the file doesn’t exist.

Directory structure

  • ./index.php
  • ./app/webroot/scripts/helpers/hamster.js
  • ./app/webroot/images/logo.png
  • ./app/webroot/style/main.css

Since you can tell the difference between a file request (/squirrel.png) and a page request (/user/profile/123) just by the existence of the file extension / dot, I was expecting that this would be really easy. But… I’m having a really hard time with it and I was hoping someone could help me out.

Something I’ve tried was…

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ app/webroot/$1 [L]

RewriteRule ^(.*)$ index.php?route=$1 [QSA,L]

… but it doesn’t really work except for redirecting correctly to existing files. Pagerequests or nonexisting files result in HTTP 500 errors.

Any help is greatly appreciated! =)

  • 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-15T16:18:16+00:00Added an answer on May 15, 2026 at 4:18 pm

    See if this works out a little more like you expected:

    RewriteEngine On
    
    # These two lines are very specific to your current setup, to prevent
    # mod_dir from doing what it does, but in a more controlled way
    RewriteCond %{THE_REQUEST} ^[A-Z]+\s/iceberg[^/]
    RewriteRule .* http://localhost/iceberg/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI}      !^/app/webroot
    RewriteCond %{REQUEST_URI}       \.[a-z]+$ [NC]
    RewriteRule ^.*$ app/webroot/$0 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI}      !^/app/webroot
    RewriteRule ^.*$ index.php?route=$0 [QSA,L]
    

    Also, to explain, the reason why you are getting the 500 error is likely because of your rule:

    RewriteRule ^(.*)$ index.php?route=$1 [QSA,L]
    

    Since it’s unconditional, and the regular expression pattern will always match, your rewrite will be performed over and over (the L flag doesn’t prevent this, because after you rewrite to index.php, an internal redirection is made inside of Apache, and the process loses its current state).

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

Sidebar

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.