You can prevent piles or hemorrhoids by maintaining a healthy diet, drinking plenty of water, exercising regularly, and avoiding straining during bowel movements.