Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PHP API main file

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

You can also take a look at this or this.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading