views:

285

answers:

1

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?

+1  A: 
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].

Mariano
One problem is /app/todo/ is a directory. But I need to force the request to /app/index.php in that case too. Second /index.php seems to redirect the request to index.php of the root directory (home page) not /app/index.php. I am trying to fix those and check what happends
CDR
Mmm, try removing the line that ends with !-d if you want to redirect directories that exist, and try either index.php or /app/index.php in the last line.
Mariano