I seem to be stuck here trying to figure out how to redirect the following scenarios:

```
/foo/index.html    -> /foo (remove trailing slash, index.html as 301)
/foo/              -> /foo (remove trailing slash as 301)
/foo               -> No redirect, shows the file at /foo/index.html
/foo/notindex.html -> No redirect, shows the file at /foo/notindex.html

```

I believe the relevant lines in my .htaccess are

```
DirectorySlash Off
RewriteEngine On
RewriteBase /

# Redirect /foo/ to /foo
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L,E=LOOP:1]

# Redirect /foo to /foo/index.html
RewriteCond %{ENV:REDIRECT_LOOP} !1
RewriteRule ^(.*)(\?.*)?$ $1/index.html$2 [L]

# Redirect /foo/index.html to /foo
RewriteCond %{ENV:REDIRECT_LOOP} !1
RewriteRule ^(.*)\/index.html$ /$1 [R=301,L]

```

but of course, the contents of the entire [.htaccess](http://pastebin.com/raw.php?i=za56zYCP) file could come in handy here too. What am I doing wrong?

**UPDATE 11/13/14**

I trashed all those rules above and am starting over:

```
# Remove trailing slash
DirectorySlash Off
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}/index.html -f
RewriteRule ^(.*)$ /$1/index.html [L]

```

This satisfies 2 of the 4 points. To be more specific:

```
1 https://server.com/foo            renders the /foo/index.html correctly without redirect
2 https://server.com/foo/           renders the /foo/index.html correctly but should redirect to /foo instead of rendering
3 https://server.com/foo/index.html renders the /foo/index.html correctly but should redirect to /foo instead of rendering
4 https://server.com/foo/foo.html   renders the /foo/foo.html correctly

```

So now that #1 and #4 are correct, how can I add 301 redirects for #2 and #3 without breaking it or looping?