0

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

toto
  • 880
  • 11
  • 21

1 Answers1

3

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
  • 57,028
  • 9
  • 76
  • 100
  • Thanks for the answer, I'm trying that right now, I'll get back to you. – toto Sep 27 '09 at 15:09
  • 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 Error The server encountered an internal error or misconfiguration and was unable to complete your request. – toto Sep 27 '09 at 15:37
  • It doesn't work, my controller.php that echoes "hello" never gets called. – toto Sep 27 '09 at 16:11