Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent one file from .htaccess redirect?

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.

like image 755
Mangala Edirisinghe Avatar asked Apr 23 '12 10:04

Mangala Edirisinghe


1 Answers

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

like image 107
RickN Avatar answered Oct 17 '22 01:10

RickN