Don't supply the domain in the rule, just the path. With the full domain it will be redirected.
RewriteRule ^embed/([^.]+).js$ /code/embed/$1 [L]
Alternately, if the resulting path is not a real file and should be handled by index.php, stip off the [L]
so that the next rule will be executed:
RewriteRule ^embed/([^.]+).js$ /code/embed/$1
Note that the mod_rewrite guide says the following, which would seem to indicate that the full URL path is okay, but I believe it compares against ServerName, not necessarily ServerAlias (I'm not 100% sure about that, but I've always used paths rather than full URLs in doing non-redirect rewrites):
Absolute URL
If an absolute URL is specified, mod_rewrite checks to see whether the hostname matches the current host. If it does, the scheme and hostname are stripped out and the resulting path is treated as a URL-path. Otherwise, an external redirect is performed for the given URL. To force an external redirect back to the current host, see the [R] flag below.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…