views:

38

answers:

1

I am doing a website with a REST architecture and I am finding the latter difficult to do. I want to be able to handle HTTP Requests like these :

GET /myapp/5445/ HTTP/1.1 ...

In an ideal world, I would code my own server and handle all the HTTP requests myself but I actually want to do this project with CGI or PHP and I want to be able to map these HTTP requests to a program that will decide wether or not it is a valid request.

With a REST Architecture, a GET /myapp/5445/ could mean "Give me resource #5445. A PUT /myapp/5445/ could mean "Create resource #5445".

This URL problem is the only thing stopping me from releasing a killer app!! :) Maybe not but thank you

I am currently working with lighttpd and CGI. If I can have an Apache solution, I will gladly switch.

By the way, this website seems to have a way to handle these non-existing URLS without calling the Error 404 handler http://pastebay.com/57208

+2  A: 

With apache you can setup a .htaccess file to forward all requests to a single controller script:

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

In controller.php you can do whatever you want with the URL.

Zed
Thanks for the answer, I'm trying that right now, I'll get back to you.
toto
I got my setup back on Apache. I created the htaccess file and I copy paste your code in it. I get a configuration now however.Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request.
toto
It doesn't work, my controller.php that echoes "hello" never gets called.
toto