How to work php front controller using .htaccess?
-
02-06-2021 - |
Question
I did front controller using the query string.
Ex:
But I need to do it without using query string.
Solution
in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (.*) controller.php [L]
</IfModule>
This will reroute everything to controller.php; so you can access it like:
http://host/main
http://host/contact_form
Then in controller.php you have to parse $_SERVER['REQUEST_URI'] to extract passed arguments.
Hope that helps..
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow