Nedas Nedas - 1 year ago 118
Apache Configuration Question

.htaccess does not open index

I decided to do a little rewriting on my site.
Currently, I have this htaccess:

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

What it does is that you can enter .php documents without adding the .php extension
, like

you can access folder/file.php by typing folder/file into the url bar.

However, now I realised that index.php is not working anymore.

If I try to enter the index via
, it works fine but it does not open it when typing just

What rule am I missing here?

Sorry I'm not used to htaccess. Thanks for your help.

Answer Source

...but it does not open it when typing just folder/

Presumably you just get a 404?

You should also exclude directories from being internally rewritten. For example:

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

So now, when you type (which maps to a directory, not a file), it won't be rewritten by the above directives and mod_dir will be able to load the DirectoryIndex.

Aside: There is an additional caveat with having the same content accessible by all these different URLs (eg. folder/index.php, folder/index and folder/) - you now have a potential duplicate content issue. Be sure to be consistent in you internal linking, include canonical meta tags and redirect if it becomes a problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download