xtiancastro7 xtiancastro7 - 1 year ago 82
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:

-- contact.php
-- index.html

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]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download