Skip to content
Advertisement

URL Routing in PHP : url routes ony to 404-Not-Found page

I have a php project in htdocs folder named “das-xampp”. The index file in the root directory works as a router. I have another index.php inside views. so the structure is as below:

JavaScript

So whenever someone types ‘localhost/das-xampp’ it should re-route the user to the index inside ‘views/index.php’ My root index(the one that works as a router) is as follows:

JavaScript

The thing is whenever I type in ‘localhost/das-xampp'(after turning on apache and mysql), the not-found php comes up. Even when I type ‘localhost/das-xampp/about-us’ manually Object not found is shown.

This doens’t happen if I use

JavaScript

All my view works fine.

not-found page

Advertisement

Answer

The problem was with .htaccess file. I didn’t include an .htaccess file which will re-route according to the routings I had in index.php file(the one in the root directory). I’m posting the .htaccess code below

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement