php – Rules and Exceptions in htaccess

Question:

I'm having a hard time setting up some routing 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 into my index, loading together all the system functions, including the default header and footer, but I need to add two pages that won't consume this header or footer. I thought doing as below would solve it, but no.

Another point, this one I think I forgot how to do is to differentiate file folders.

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]

In 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;

Answer:

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 clear the cache

I hope it helps

Scroll to Top
AllEscort