The RewriteCond is both meaningless and unnecessary, since it means "the host is anything or nothing". That about covers all possibilities doesn't it ;)
Leave a blank line after each RewriteRule. Not for Apache's sake but for your own; among other things it reminds you that a RewriteCond applies only to the immediately following rule.
The following are unnecessary:
-- quotation marks in the target
-- all escapes in the target (some characters have to be escaped in patterns and conditions, but never in targets)
-- escaped colon (NEVER necessary in Apache afaik, and probably not in any other RegEx dialect)
-- escaped slashes (necessary in those Apache mods and programming languages that use / itself as a RegEx delimiter, otherwise not needed)
-- as previously noted, the closing anchor in both patterns, and the opening anchor in the second pattern
Aside from that, the first rule as written
RewriteRule ^directory?(.*) http://www.b.com/directory/$1.html
optionally followed by more stuff-- meaning that the pattern could have said "director(.*)" except that this isn't what you meant anyway --will be redirected to
olddirectory/ is captured as
olddirectory(/) which redirects to
olddirectory/filename is captured as
olddirectory(/filename) which redirects to
olddirectory/filename.xtn is captured as
olddirectory(/filename.xtn) which redirects to
In short: It's adding the extra slash because you told it to. The obvious fix is to include the slash in your capture as
It's .+ rather than .* because if the request is for directory/ or directory (no slash) alone, mod_dir steps in and you don't need to do anything on your own. The closing anchor becomes necessary the moment you add the [^.] meaning "don't do this if the request already contains a literal period". It's to prevent the RegEx from stopping halfway and pretending it hasn't seen the upcoming period.
Which reminds me that you will need a preceding RewriteCond to deal with requests for /directory/index.html. There should not be any, of course, but you have to code for them. If nothing else, search engines will sometimes ask for this file just to see what will happen. The exact format of the Condition will depend on your existing index file name.