I am developing an e-learning website and there is a course preview page for each course on the platform. the file structure of the platform is something like https://example.com/courses/[course_id...]/index.php
and the PHP code gets the course id from the parent directory name to look it up in the database. The problem here is that I have to make the same copy of the index.php
file in each course directory I make, so is there a way to modify the .htaccess
file in a way that I can have only one copy of the index.php
file?
2
Answers
Let’s assume you have a file named course.php. This file pulls up a course based on ID at a URL like:
http://localhost/course.php?id=1
In your .htaccess
Then you can go to http://localhost/courses/1 to get course ID 1.
https://httpd.apache.org/docs/2.4/rewrite/intro.html