"on the doorposts of your house": on the right as you enter? or on the right as you leave? It is, therefore, written "on the doorposts beitecha" (similar to "biatecha") ["your coming in"] — on the right hand side as you enter.
"and on your gates": Both the gates of houses, courtyards, countries, cities, stables, poultry houses, hay lofts, wine cellars, oil stores, and granaries are included in the mezzuzah requirement.
I might think that also included are a gate-house, a corridor, and a terrace; it is, therefore, written "house." Just as a house is intended for living purposes, (so all that are thus intended) to exclude the above, which are not thus intended. I might think that also included are privies, tanning houses, and bathhouses. It is, therefore, written "your house." Just as "your house" connotes a place of dignity, so, all such places (are included), to exclude the above, which are not thus intended.