Linking to a website only through another site
I have two websites: Website1 and Website2
I would like to prevent people from linking directly to Website2 by writing its URL in a browser. However, I would like them to have access to Website2 by clicking on a link in Website1. In other words, if the referrer is Website1 then access to Website2 is ok. Otherwise, I would like to block all other referrers, including people typing a URL directly into a browser.
I believe it is possible to control access through .htaccess. Would someone please point me to some code I could implement in .htaccess or somehow otherwise restrict access as indicated above?
BTW I have tried using deny and allow but that only seems to apply to addresses typed in the browser. I believe there is an answer which uses the rewrite engine but I have not been able to find the correct code anywhere.
Thank you very much.