I have a question concerning an API that I am developing and I have just started asking myself the following question: As a rule, to reach the main file, you have to reach it in the following way api.domain.com/index.php/users/id/profile/... but many sites allow you to avoid calling the file index.php but put the "query" directly. My question is, what should I do in order not to enter the file name, since if I don't put index.php it goes missing because it sees the query as folders Any ideas?
Translated with www.DeepL.com/Translator (free version)
CodePudding user response:
You could use .htaccess file.
As an example, you may add this to your .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L,QSA]
And then use some sorte of routing (like FastRoute or Laravel routes) to redirect the user where you wanted. This way, you could call api.yousite.com/users/id/... and it'd go through the index.php anyway.