Rules and Exceptions in htaccess

Asked

Viewed 128 times

3

I’m having a hard time setting up some route rules in my .htaccess, I originally have the following (I accept suggestions for improvements):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Everything is loaded in my index, loading together all the functions of the system, including the header and the default footer, but I need to add two pages that will not consume of this header or footer. I thought doing as below would solve, but no.

Another point, this I think I forgot how to do is to differentiate folders from files.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

RewriteRule ^login/?$ /login.php [NC,L]
RewriteRule ^start/?$ /start.php [NC,L]

On my index, I have:

$modulo = Url::getURL(0);

if($modulo == null or $modulo == 'index.php'):
    $modulo = "dashboard";
endif;

if(file_exists($modulo.".php")):
    require $modulo.".php";
else:
    require "404.php";
endif;

2 answers

1


One possibility is to create the same conditions for each rule

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^login/?$ /login.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^start/?$ /start.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

Remember to delete the cache

I hope it helps

  • I will test on the project here. Thanks for your attention.

  • The second option worked perfectly, already first caused a loop and gave error 500.

  • 1

    I updated the post leaving only what works

-4

Example:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_Host} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_Host} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir/index.php [L] 
</IfModule>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.