.htaccess将domain.com重定向到domain.com/

Is it possible to use a .htaccess file to redirect mydomain.com to mydomain.com/

I tried:

RewriteRule ^(.*)/$ http://%{HTTP_HOST}/$1

which should work for any URL on the domain however it only works for non-root URLs (Above code removes trailing slash rather than adds it, however I wanted to see if it'd work for root URLs).

There was also the solution from here which is:

RewriteCond %{THE_REQUEST} ^([A-Z]{3,9})\ (.*)//([^\ ]*)
RewriteRule ^ %2/%3 [R=301,L]

This removes multiple trailing slashes (ie mydomain.com// becomes mydomain.com/) but still doesn't work for mydomain.com -> mydomain.com/

I'd even accept a way to do it with PHP if that's available.

Try:

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L]

http://mydomain.com and http://mydomain.com/ look exactly the same to the webserver, the URI is / for both of them. You're not going to be able to force the browser's address bar to have a trailing slash after the domain from .htaccess or php.