How do you set a 301 redirect in .htaccess to add the forward slash to your document root if someone links to you without it?
According to the research I have done most search engines consider the following URL’s as two different URL’s.
mydomain.com (no forward slash)
mydomain.com/ (forward slash)
I’ve tried this (plus many others):
RewriteRule ^$ http://www.mydomain.com/ [R=301,L]
That throws it into a loop loading the page over and over.
I think you drew incorrect conclusions out of your research. For HTTP, the Root-URL without forward slash is specified to be equal to the forward slash:
Hence, if the original URL is only a domain name that does not end with a forward slash (i.e. the absolute path would be empty), that URL will be extended by a forward slash. You don’t have to do anything.
As for your problem: Due to the subtleies of mod_rewrite, the first slash is ommited, so your RewriteRule captured the root URL and sent the requester in a redirection-loop.