Of course, this just raises the question of what exactly the D&D rapier is supposed to be. Given that what D&D calls a longsword is nothing like what modern Hema does,
How? It is a longish sword that can be used with either one or two hands. That's what a longsword usually means.
Historically a longsword is a term for a sword primarily wielded with both hands, usually 4'+ in length. Filippo di Vadi wrote that the total length should come up to the wielder's armpit. The grip/hilt is long enough to easily accommodate both hands (for example I'm looking at a 51" example right now with a 10.25" hilt). This is typically too long to be wielded comfortably or deftly with a single hand, though you can certainly release one hand on a swing to briefly extend your reach (albeit at the cost of power, so you wouldn't want to do that against armor).
A longsword as depicted and described in D&D is shorter and primarily wielded in one hand. The dimensions and characteristics the various editions give correspond more closely to historical weapons called variously an arming sword,
knightly sword, or (earlier) viking sword or spatha, and perhaps the later
cut & thrust sword. It's short enough to be wielded comfortably in one hand (and with a shield) and worn on a belt without constantly dragging on the ground.
1E AD&D lists a longsword as 3.5' in length, alongside the Bastard Sword at 4.5' in total length, a better fit for the historical longsword (and tells you to treat the bastard sword as a longsword if wielded one handed). The 2E Arms & Equipment guide says longswords range from 35" to 47" inches, with the latter having a 7" hilt, and notes that "the handles of all long swords fit only one human-sized hand". 3rd ed doesn't specify length but defines a longsword as a one handed weapon. (Bastard swords are classified as exotic weapons requiring a feat to wield in one hand without a -4 penalty, but usable two handed as a martial weapon). 4E also fails to specify length for the longsword and classifies it as one handed, but adds the Versatile property, allowing it to be wielded in two hands for an extra point of damage. 5E followed this example, though increases the die size to d10 instead of adding a +1. So in this way the 5e longsword has come to resemble the historical one a little more, though you'll still normally see people wielding a "real" two hander if they don't want a shield.
Obviously real world sword dimensions are highly variable and categorization can be a bit murky about the edges, especially in transitional periods as one common form is being replaced by another, but D&D calling a single handed blade a longsword has been a bit of a meme and lighthearted complaint among sword nerds for decades. OSR game 5 Torches Deep calls its single handed swords "arming swords" and its two handed swords "longswords".