Reputation:
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
Upvotes: 0
Views: 149
Reputation: 655319
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]
Upvotes: 1
Reputation: 95364
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.
Upvotes: 0