Question

I have my application entry point like this.

/app/index.php <-- this is the main dispatcher.

And application specific folders under /app/

/app/todo/
/app/calendar/
/app/bugtrack/

Each application folder cotains application specific files.

I would like to pass all requests unders app to pass through /app/index.php.

So that.

/app/todo/list/today -> goes to /app/index.php
/app/ -> goes to /app/index.php
/app/bugtrack/anything/else goes to /app/index.php

On my lighttpd test machine I can easily do it it by writing a rule like this.

url.rewrite-once = (
    "^\/app\/todo\/*"   => "/app/index.php",
    "^\/app\/calendar\/*"   => "/app/index.php",
    "^\/app\/bugtrack\/*"   => "/app/index.php",
)

Now need to make it work on Apache using .htaccess and mod_rewrite.

But no matter what I do, it's not working.

I wrote the following in /app/.htaccess

RewriteEngine on
RewriteRule .* index.php [QSA]

It works for /app/ and /app/todo/ but fails for /app/todo/list/today for example.

Anyone can give me any idea how to do it?

Was it helpful?

Solution

RewriteEngine On
RewriteBase /app
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

What this does is if the request is not a filename or a directory, rewrite it to index.php. Then check $_SERVER[REQUEST_URI].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top