xtiancastro7 xtiancastro7 - 2 months ago 12
Apache Configuration Question

Using .htaccess for remove .php extension but folder access returns 404

I'm using this .htaccess for remove .php in my URLs

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]


My files structure is this:

css/
es/
-- contact.php
-- index.html
js/
contact.php
index.php


What I'm trying to create is a link in my main index.php like this:

<a href="es/">EspaƱol</a>


But when I try to access it, my server returns a 404 error. When I delete the .htaccess, this link works fine, so I guess that I need something else in the .htaccess. Can anybody please guide me on what do I have to add for this to work?

Answer Source

With test for php and without folder:

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