Business entities register their names iwth the California Secretary of State. After that, they can have an unlimited number of "fictitious business names". A company can also have an unlimited number of domain names. Some may be related to products or services offered by teh company, others not. A company has to apply for each new domain name and pay for the registration. Domain names and trademarks are totally independent, except that cannot select a domain name that contains the registered trademark of another.
The above is general legal and business analysis. It is not "legal advise" but analysis, and different lawyers may analyse this matter differently, especially if there are additional facts not reflected in the question. I am not your attorney until retained by a written retainer agreement signed by both of us. I am only licensed in California. See also avvo.com terms and conditions item 9, incorporated as if it was reprinted here.
A company need not use the exact same name in all instances (it can use a d/b/a or "doing business as" name). Also, sometimes a company is given an "unofficial" nickname by the public (such as HoJo for Howard Johnson's Motor Lodge, or FedEx for Federal Express, Inc., which the company may later adopt officially). However, using different names (or frequently changing it) is contrary to the goal of building a brand name, and may weaken your trademark rights.
Sometimes the desired domain name is unavailable, so a company obtains a different domain name that does not exactly match the official corporate name. In that situation, the domain name would be registered in the name of the corporation (unless the corporation uses a proxy registration service).
If someone "had used the name "facebook" 20 years ago (but not registered) for a couple of weeks and then abandoned it"--then it would be abandoned and, in general, that person has no rights to it (although there currently is some litigation regarding famous retired marks).
This answer is for informational purposes only. It is not intended as specific legal advice regarding your question. The answer could be different if all of the facts were known. This answer does not establish an attorney-client relationship.
Generally, a company can be registered as one entity; i.e., Cellco, use a different name when doing business over the Internet; i.e., Verizon Wireless, and use a different URL for their web site; i.e., www.vzw.com (they also use www.verizonwireless.com). As far as being able to use different web names, that is very common - for example, when new products are introduced, many companies will register URLs that are relevant to the new products.
As far as how this plays out with trademark rights, that is also a good question. In the circumstance that you described, where someone had used the mark "Facebook" for a short time and then abandoned it, the mark Facebook would again be available for use; i.e., there would not be a trademark issue. These issues come up all of the time, even when a party does register their mark, in that trademarks that fall into disuse (or become generic due to too much use) cease to be operative as trademarks (irrespective of registration).
This answer is not a substitute for professional legal advice. This answer does not create an attorney-client relationship, nor is it a solicitation to offer legal advice. If you ignore this warning and convey confidential information in a private message or comment, there is no duty to keep that information confidential or forego representation adverse to your interests. Seek the advice of a licensed attorney in the appropriate jurisdiction before taking any action that may affect your rights. If you believe you have a claim against someone, consult an attorney immediately, otherwise there is a risk that the time allotted to bring your claim may expire.
Once you register your business name, you can use as many DBA's or domain names as you want (although in must states you need to register your DBA's). The problem here, however, is not registration. The problem is that before selecting names or trademarks, it is vital for you to retain counsel to conduct a trademark clearance analysis. Otherwise, you might invest heavily in using a name, only to find that you have to find another one, wasting your investment in branding. Branding a company requires a combination of corporate and IP law expertise, and this is not a DIY job---you need counsel to advise you every step of the way.