How to prevent redirection of one file from .htaccess?

I am creating a php front controller. this is my file .htaccess.

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    (.*) controller.php    [L]
</IfModule>

This code redirects the entire url to controller.php. I need to avoid redirecting index.phpto controller.php. All other URLs should be redirected to controller.php.

+5
source share
2 answers

You can use the following syntax to exclude:

RewriteRule name_of_page_to_exclude.php - [L]

Trait ( -) is important. [L]ensures that if this rule is run, it will be processed last. Therefore, naturally, you need to place it near the top of your file .htaccessbefore the rule in your question:

RewriteEngine on
RewriteRule name_of_page_to_exclude.php - [L]
RewriteRule (.*) controller.php [L]

The documentation states the following:

- () , ( ).

+5

:

RewriteCond %{REQUEST_FILENAME} !-f

, , , .

0

All Articles