Answer:
Rabbits get worms and other parasitic infections from their environment -- sometimes from eating contaminated grass or other vegetation, and sometimes from an insect (like a fly) laying its eggs directly on the rabbit.
If you notice that your rabbit has worms, you should bring it to a special "rabbit-savvy" vet for an examination: some parasites are relatively harmless, but others are life-threatening, so you should find out which is affecting your rabbit immediately.
You can prevent parasitic infections by keeping your rabbit indoors and not feeding it fresh grass. If you keep your rabbit outdoors, speak to your vet about ways to prevent infections and/or manage parasites around your rabbit.
See the related questions below for some helpful info and links.