删除htaccess中的尾部斜杠

i have been having trouble with my htaccess. I tried removing the trailing slash, but get a error that says "This webpage has a redirect loop". My current htaccess is:

ErrorDocument 404 /404/
RedirectMatch 301 ^(.+)/$ $1

Before you answer I have already looked at other sources in stackoverflow, they all give me the same error, except some give me a "500 internal server error". So please don't post it as a duplicated :)

Have it this way in your root .htaccess:

ErrorDocument 404 /404/

RewriteEngine On

## Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [NE,R=302,L]

Test it after clearing your browser cache. After testing is complete change 302 to 301 to make it a permanent redirect.