如何防止.htaccess重定向中的一个文件?
I am creating php front controller. this is my .htaccess
file.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule (.*) controller.php [L]
</IfModule>
This code redirect all url to the controller.php
. I need to avoid redirect index.php
to the controller.php
. All other urls should redirect to the controller.php
.
You can use the following syntax to make an exception:
RewriteRule name_of_page_to_exclude.php - [L]
The dash (-
) is important. The [L]
makes sure that if this rule is triggered, it's the last one that will be processed. So naturally, you'll need to place it near the top of your .htaccess
file, before the rule in your question:
RewriteEngine on
RewriteRule name_of_page_to_exclude.php - [L]
RewriteRule (.*) controller.php [L]
The documentation has the following to say:
- (dash) A dash indicates that no substitution should be performed (the existing path is passed through untouched).
Add the following condition :
RewriteCond %{REQUEST_FILENAME} !-f
This shall allow any files that actually exist and assumes it wouldn't mess up anything else for other files that already exist.