The gut microbiota is a changing ecosystem, containing trillions of bacteria, continuously shaped by many factors, such as dietary habits, seasonality, lifestyle, stress, antibiotics use, or diseases. A healthy host–microorganisms balance must be respected in order to optimally maintain the intestinal barrier and immune system functions and, consequently, prevent disease development. In the past several decades, the adoption of modern dietary habits has become a growing health concern, as it is strongly associated with obesity and related metabolic diseases, promoting inflammation and both structural and behavioral changes in gut microbiota. In this context, novel dietary strategies are emerging to prevent diseases and maintain health. However, the consequences of these different diets on gut microbiota modulation are still largely unknown, and could potentially lead to alterations of gut microbiota, intestinal barrier, and the immune system. The present review aimed to focus on the impact of single food components (macronutrients and micronutrients), salt, food additives, and different dietary habits (i.e., vegan and vegetarian, gluten-free, ketogenic, high sugar, low FODMAP, Western-type, and Mediterranean diets) on gut microbiota composition in order to define the optimal diet for a healthy modulation of gut microbiota.