I'm using a main index.php file to handle the most of requests, so my basic .htacess looks like this one:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?page=$1 [L]
But i've got some requests (like /signin or /signout) that needs to be handled directly from .php file with the same name (/signin.php and /signout.php).
So my .htaccess rules needs to be: "if %{REQUEST_FILENAME}.php does not exists redirect to /index.php?page=$1 else redirect to %{REQUEST_FILENAME}.php".
How can i do this?
Replace your code with this:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteRule ^(.+)$ /index.php?page=$1 [L,QSA]
This will send everything to /index.php that is not a valid file or directory and doesn't have a matching .php existing in your filesystem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With