probablybest
probablybest

Reputation: 1445

Update .htaccess to allow specific directory link to work without having to go to index

I'm using the follow code in my .htaccess file to remove the need for the file extension .html on my site.

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

This is all working great. However I have a subdirectory with an index file which you currently have to access via /subdirectory/index/ . I would like to target this subdirectory in my .htaccess file to allow it so that I can write /subdirectory/ and it still load the index page.

Currently if I go to /subdirectory/ I get the following error:

You don't have permission to access /subdirectory/.html on this server.

Is there a way around this?

Upvotes: 0

Views: 26

Answers (1)

George
George

Reputation: 36784

Add another rewrite condition, to test weather the given path is an existing directory:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([^\.]+)$ $1.html [NC,L]

Upvotes: 1

Related Questions