This is my first time using PHP/MVC architecture and
The problem is an error 404. I’m using MVC architecture with php.
The process should be working like this:
1.The Router gets the current URL and the method used with
$_SERVER['REQUEST_URI']
$_SERVER['REQUEST_METHOD']
2.The router gets an specific function for the current URL. Said function is defined on index.php in PUBLIC for ever URL of the project
3.The router calls the function. The functions are in the Controller.
call_user_func
This is only working for the Main Url (defined as ‘/’ in the index.php from PUBLIC).
Whenever I want to access any other URL I get the 404 error. It’s like if the server couldn’t access the folder with the VIEWS.
But I know it works because the VIEW index.php is rendering the URL ‘/’. I tried exchanging the functions called by the URL’s to see if there was something wrong with the Classes or anything else, but it also worked (example: I called the function "contact" from the URL ‘/’ instead of the function "index" and I got the correct ‘/contact’ VIEW)
I’m sure my project is working on my localhost.
I even deployed it on another CPanel and it work correctly, the difference is that the other is a VPS and the one with the problem is a shared hosting.
From what I can understand is that the issue should be one of the following:
-the htaccess file
-the php ini
-the composer autoload is not working
My php version is correct and my database is working properly.
Was I able to explain my problem? Send Help Please!
Here’s my code for the Router and index.php on PUBLIC
2
Answers
Nevermind I solved it If out there's any noob like me witht the same problem... I solved with the htaccess file
it should be like this
And it should be in the same folder as your index.php (PUBLIC folder)
I’m facing the same problem but wasn’t able to fix it. I can’t access other files. Here is my project dir
here is my htaccess file: