Link to home
Start Free TrialLog in
Avatar of Brant Snow
Brant Snow

asked on

PHP REST API Intro

I am going to be working on a api that use only using GET requests
i would like the parameters to be within the url statement rather than url parameters so

www.site.com/json/movie/en/US

rather than www.site.com/json/index.php?part=movie&language=en&country = US

My question is how do i get something like www.site.com/json/movie/en/US to actually run a script or php page.  Im used to running say mypage.php and adding url parameters on to it.  How can www.site.com/json/movie/en/US launch mypage.php then how do i grab the resources out of the url so i have vars such as $country set up with US using my script.
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Avatar of Brant Snow
Brant Snow

ASKER

So do i have to write multiply mod rewrites because well i dont know if they are going to hit

www.site.com/json/movie/en/US  or maybe

www.site.com/json/movie/es/CA , so if that was the case would i have to include  a mod rewrite for every possibility?
SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you have a script, "/json.php", you can use a URL like "/json.php/movie/en/US".  The trailing "/movie/en/US" part is just an argument.  The trick, if you want to have that first part be "/json" (without ".php"), is to create a file called "json" in the same place that the "json.php" file would be, and add this to your .htaccess file:
<files json>
        ForceType application/x-httpd-php
</files>

Open in new window


Apache determines how a file should be parsed based on it's extension; since the file doesn't have an extension, you have to tell Apache how it should be parsed.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial