Somenath Sinha
Somenath Sinha

Reputation: 1214

Site broken after modifying .htaccess file

I recently added these lines to my .htaccess file on the server:

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

What I was trying to do was eliminate the need for .php after the file name. This worked wonderfully, but something else was broken.

The URL for the website was http://subdomain.something.domain/eCom/ and I had an index.php file in it, which was automatically loaded when the above link was used. But after editing the .htaccess file, the above link returns a 404 error. The page still opens correctly if I use http://subdomain.something.domain/eCom/index or http://subdomain.something.domain/eCom/index.php. I don't know what's happening. Anyway this can be resolved?

Note: I don't understand the code above about all the RewriteEngine stuff. I just copied from a website hoping for a quick fix. Any additional information about it is welcomed, if that's what's breaking my code.

Upvotes: 1

Views: 261

Answers (1)

Blue
Blue

Reputation: 22911

Add RewriteCond %{REQUEST_FILENAME} !-d above your first RewriteCond to avoid matching directories as well.

Upvotes: 2

Related Questions