Search code examples
php.htaccessfront-controller

How to work php front controller using .htaccess?


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..