REST / RESTful Apache Server Setup

Discussion in 'Apache' started by Fyodor, Mar 31, 2009.

  1. #1
    Hello everyone!

    I have been trying like crazy to get Apache setup in a way to redirect all URLs in a certain directory passed to a PHP file for processing.

    For example...

    http://www.example.com/api/cats/234324
    http://www.example.com/api/dogs
    http://www.example.com/api/geese/34234

    I would like all of these URLs (http://www.example.com/api/*) passed to a PHP file for processing. Also, just to make sure, once received at the PHP file, the original URL must be able to be accessed for processing.

    I thought I was on the right track with
    <LocationMatch "/api/*">
    SetHandler "index.php"
    </LocationMatch>

    But that didn't seem to work at all. I have full access to the Apache server.
     
    Fyodor, Mar 31, 2009 IP
  2. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You have to post the original structure of the PHP file URL. (parameters)

    Thanks.
     
    Lpe04, Mar 31, 2009 IP
  3. Fyodor

    Fyodor Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi Lpe, thanks for the quick response.

    The PHP file has no contents yet, I am the one that will be writing it; was that your question? I haven't decided the URL yet either, I was thinking either...

    http://www.example.com/api/index.php
    or
    http://www.example.com/api.php

    I hope those answered your questions ? If not please dumb them down for me. This is the first time I've really messed with configuring Apache.
     
    Fyodor, Mar 31, 2009 IP
  4. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, you need parameters, such as

    index.php?page=soandso

    Unless you just want everything to display index.php (but they will all look the same), that is easy to do.

    Cheers,
     
    Lpe04, Mar 31, 2009 IP
  5. Fyodor

    Fyodor Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    So this is what I've come up with.

    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^/api/.+
    RewriteRule ^/(.+)$ /api.php

    Works like a charm. The $_SERVER['REQUEST_URI'] and $_SERVER['QUERY_STRING'] PHP vars are both still from the original request, so I can process them easily.
     
    Fyodor, Mar 31, 2009 IP
  6. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #6
    cool, by the way you should be able to take out that first part if you wanted to.

    RewriteRule ^api/(.+) api.php [L]

    But it doesn't matter. Cheers,
     
    Lpe04, Mar 31, 2009 IP