Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make .htaccess work on the current directory and not subdirectories?

I'm using mod rewrite to access my PHP files in the root directory of my website indirectly. Currently, I have something like this,

RewriteRule ^(blog|about|page3|etc)$ /$1.php [L]

But what I would like to use is

RewriteRule ^(.*)$ /$1.php [L]

So that I wouldn't have to update my .htaccess file whenever I wanna add a new page to my website. The problem with this however is that it affects my subdirectories too. Which makes CSS, javascript, images unaccessable because it redirects to "/dir/example.png.php".

So what is the best solution here?

like image 518
fent Avatar asked Jan 23 '23 09:01

fent


1 Answers

Try this rule:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule .* $0.php [L]
like image 52
Gumbo Avatar answered Jan 25 '23 23:01

Gumbo