Anchor the rug. Tuck the edges of the rug under a heavy piece of furniture at either end. Make sure the rug is pulled tightly to prevent wrinkles. Keep in mind, however, that the heavy furniture will leave impressions on your rug.
Use Velcro tape. Velcro tape is sticky on both sides, which allows you to attach one side to the carpet and the other to your rug. Then, link the two Velcro pieces together. Place Velcro tape at every corner, and consider using the tape along all of the edges of your rug. If you have a long fiber carpet, however, Velcro tape may not stick to the fibers.
Try a product called a Rug on Rug Hold. It is a very thin mat that you place between your rug and carpet. One side of the mat has a sticky surface. Peel away the protective covering and place the sticky surface onto your rug. The other side of the pad has fibers that will grab the carpet.
Try a rug grip. This is not as thin as the Rug on Rug Hold, but it works well. It is one solid sheet made of rubber. The more traffic your rug will get, the thicker the sheet of rubber you should buy. Some cheap versions fall apart quickly, however, so look for more expensive rug grips.
Avoid taping or nailing the rug down. Tape will leave sticky residue all over your carpet, and nails, besides being unsightly, will stretch the rug and eventually tear it.