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.
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.
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:
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.
<files json>
ForceType application/x-httpd-php
</files>
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.workingwith.me.uk/articles/scripting/mod_rewrite
http://www.modrewrite.com/