when a person arrives at domain.com/variable I am using htaccess to rewrite the url to become domain.com/?ref=variable
Your Rewrites are a bit garbled. Before you start...
#1 get rid of the <IfModule... envelope. Not its contents, just the <If and </If lines. They are standard CMS boilerplate, but now that you are in your own htaccess you don't need them. You either have mod_rewrite or-- horrible to contemplate-- you don't.
#2 the line "RewriteEngine On" only needs to occur once per htaccess, before the first Rewrite.
#3 RewriteBase / will do no harm but is rarely necessary, especially in htaccess. / is the default.
#4 Leave a blank line after each RewriteRule so you can see where one starts and another one ends. #annotate the Rules so you will remember what they are supposed to do.
In the (I assume) boilerplate part of your .htaccess, there are two Rules:
If request is for index.php, stop rewriting and proceed to next module.
If request is for anything else,
and the "anything else" doesn't really exist (the !-f and !-d lines), then serve content from index.php, keeping the existing query string if any.
Both of these rules collide with (assuming again) your added rule:
RewriteRule ^([0-9a-zA-Z-_]+)$ index.php/?ref=$1 [R,L]
This Rule-- which comes before the other two-- takes
any incoming single-word extensionless request, captures it, and 302 redirects to the directory index.php/ replacing the old query string, if any, with the name of the requested file.
Even setting aside the existing-files problem, this is exactly the opposite of what you want to do. Do a quick search in this Forum for the pair of words Rewrite and Redirect. There's a bit of recent boilerplate which I'm pretty sure corresponds to what you're trying to do.
Narrower answer: the difference between /members and /members/ --assuming that's a real directory-- is that one version has met mod_dir (or was correctly entered in the first place) and one hasn't. That's what the !-d line is for, but in real life the Cond should be more exactly coded.
No, I don't know why every single question I've seen in the past 24 hours seems to involve directory-slash redirects at some point.