Peter Bennett
Peter Bennett

Reputation: 194

HTACCESS file extention removed, but can't access index file because of directory and file conflicts

Having problems finding a solution to this...

I have removed all file extensions from the url with the following .htaccess script.

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

But when I try to access a directory it throws me to our standard 404 page.

For Example:

www.website.com/directory-name/page-name (works)

www.website.com/directory-name (does not go to index or directory-name.php) even though they both exist.

Thanks for your help

Upvotes: 1

Views: 23

Answers (1)

Amit Verma
Amit Verma

Reputation: 41249

You need to exclude existent dirs from the RewriteRule :

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

Upvotes: 1

Related Questions