Question

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

Was it helpful?

Solution

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.

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