I come from a C# MVC background but I am currently working on a PHP project.
In C# you can setup decorators to specify the request URL using something along these lines:
[HttpGet]
[Route("/ControllerName/ActionName")]
public string MyAction() {
// ...
}
I am wanting to set something similar up in PHP, so I set my file structure like this:
+ assets
+ css
+ javascript
+ images
+ server
+ api
+ controllers
- index.php
+ ui
+ area1
- view1.html
- view2.html
+ area2
- etc.html
- .htaccess
- index.html
Where index.html is my login page, the other html pages live in their respective /ui/area
directory, and my restful API pages live in /server/api/controllers
. The /server/api/index.php
follows a very similar pattern to this Stack Overflow answer: https://stackoverflow.com/a/1737903/1920035
In my .htaccess
file, I have the following redirect rule setup:
# Redirect traffic starting with /api to the /server/api/index.php file
Redirect 301 ^(api/.*)$ /server/api/index.php [L,QSA]
The idea is that if I hit /api/account/get
that it will redirect to the /server/api/index.php
file and run its magic to run the respective controller/action.
The issue is that when I spin up my server and hit the pretty URL that it always returns a 500 response without any useful response text.
To complicate things, I'm running Docker for Windows using php:8.2.2-apache.
What am I doing wrong here? I do not have much experience setting up .htaccess files and with a vague 500 response, I don't have much to go off of.