This question is hard to answer because there are so many moving parts, but the essential information (in my view) is this:
1) A website is NOT a business.
A business is an organization engaged in the trade of goods, services, or both to consumers or other businesses. A business is essentially a legal entity that exists as the result of a legal/paper filing with a state/gov organization, and has a degree of personhood in that it can conduct business, execute contracts, own assets, and do many other things on it's own.
A website for a business is a series of files/images/assets that is hosted and made available on the internet, usually so that the public can interact with the site to conduct various transactions related to the business. The business OWNS the website and the website performs functions FOR the business, but they are not the same.
For example, the business could sell the entire website but the business would still exist without it. The website would no longer be associated with that business, but could easily be purchased and used by another business.
The website is a tool for the business and nothing more. Imagine a construction business that owns an expensive crane. The crane is critical to their business but it's just an asset and could be sold to another company easily.
2) Given that the website is simply an asset of the business, it can be bought, sold, shared, or otherwise transferred around according to whatever legal arrangements exist. If you sign a deal with the client that grants them exclusive rights and use of the website then they could own it outright. If you sign a deal with the client where you grand them a non-exclusive and maintian the right to sell the code, that could be OK to.
So, in your legal agreement you simply need to have some very clear language about what you are building for them and who will own what once the project is done.