I want to write a simple web api only in php. I know how to determine the type of request and the parameters of the request. There is a folder api in which the index.php is stored which processes requests. I can not understand how to do the routing in requests, ie the request webapi / api / product / 1 will go nowhere. How can this be done?

    1 answer 1

    It is necessary to register in the .htaccess file

     RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^(.*)$ ./index.php?route=$1 

    Everything after www.site.com/ gets into $ _GET ['route']

    If you need a slightly different rule, I advise in a search engine to search for htaccess редирект на index.php