views:

37

answers:

2

Hi, when I first set up my site I decided to add index.html to the URL but now I have problems with when people remove the index.html and try and access the folder...

For example:

RewriteRule ^archives/([0-9]+)/([0-9]+)/index.html archive.php?mid=$1-$2

So when archives/07/2009/ it will cause an error, how can I avoid this error? Cheers

A: 

Make the index.html optional in your RewriteRule:

RewriteRule ^archives/([0-9]+)/([0-9]+)/(?:index\.html)?$ archive.php?mid=$1-$2

Also, in your original rewrite rule, you forgot your end of string anchor $. I've added it above.

Andrew Moore
fantastic! Thanks
+1  A: 

Try this rule witht an optional index.html:

RewriteRule ^archives/([0-9]+)/([0-9]+)/(index\.html)?$ archive.php?mid=$1-$2

But I recommend you to stick just with one of both notations, with or without the trailing index.html and redirect if wrong:

# remove index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?index\.html$ /$1 [L,R=301]

# add index.html
RewriteRule (.*)/$ $1/index.html [L,R=301]
Gumbo
**@Gumbo:** You might want to make `index\.html` a non-capturing group.
Andrew Moore
@Andrew Moore: Non-capturing groups are only available since Apache 2.
Gumbo