Your rules are wrong. You have this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ gallery.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ gallery.php?id=$1
</IfModule>
^([a-zA-Z0-9_-]+)$ will match everything in the URL after the first slash, as long as there is no slash. There's a slash in mainsite.com/favs/7, so the rule doesn't match, and it looks for an actual directory named /favs/7. What you want is to match only the piece after favs, like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^favs/([0-9]+)/?$ favs/gallery.php?id=$1
</IfModule>
The code above is what you should put in .htaccess if it is in your root directory. If it is in your /favs directory, then you need to remove the /favs from RewriteRule and add a RewriteBase like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /favs
RewriteRule ^([0-9]+)/?$ gallery.php?id=$1
</IfModule>
Note: based on your question, I have eliminated letters, _, and - from the regular expression. If you need to match them, you can tweak the rule above accordingly.