Redirect all to index.php using htaccess?

Posted by Editorial Staff | Updated on

In this example, We have shared how to redirect all to index.php using htaccess? First make sure that your .htaccess file is in your document root (the same place as index.php) or it’ll only affect the sub-folder it’s in (and any sub-folders within that – recursively).

Next make a slight change to your rule so it looks something like:

At the moment you’re just matching on . which is one instance of any character, you need at least .* to match any number of instances of any character.

The $_GET[‘path’] variable will contain the fake directory structure, so /mvc/module/test for instance, which you can then use in index.php to determine the Controller and actions you want to perform.

If you want the whole shebang installed in a sub-directory, such as /mvc/ or /framework/ the least complicated way to do it is to change the rewrite rule slightly to take that into account.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers