The first rule of toenail fungus is that it lives and thrives in a damp, warm environment. If you find yourself in frequent situations where your feet are moist due to wet socks and shoes, you're at risk. Whether that's because you live in a humid area or you work in conditions where your shoes get wet, you ought to find ways to change your socks and air out your shoes often. If possible wear synthetic socks that wick away moisture. If you've got an old pair of sneakers or shoes that are moldy, trash them. Get a new set.
It's a good idea to go to the store and find a good anti-fungal foot powder. Use this every day. If you sweat frequently it's best to get in the habit of sprinkling this on your feet frequently, to combat possible fungus.
If you haven't learned yet, this is a good time to put into practice a good toenail trimming routine. You should clip your nails short; don't let them go too long and grow too long! Clip across the nail and file down any areas that are becoming thick. Keep your feet dry and make sure they're not dirty.
You must also be aware of the areas where you walk, especially if you're accustomed to strolling around in bare feet. If you make a habit of walking around in damp public areas - like swimming pools, public showers, locker rooms, gyms - you're taking a serious gamble. You need to know that fungus is passed from person to person, and areas like this are ripe for that transfer to happen. Get out of your habit of being barefoot, and put on a pair of sandals or waterproofed shoes. You may find it inconvenient, but it will prevent a real problem down the road.
If you like to wear nail polish or affix artificial nails, you could be also putting yourself at risk for an infection. Much like covering up with damp socks and shoes, covering up the beginnings of a fungal infection with polish or fake nails traps moisture and fungus and creates another favorable place for it to grow. It may be best to allow your nails to stay clean and dry.
Continuing on the subject of beauty and cosmetics, make sure to go only to a reputable nail salon for your pedicures. Know that fungus can also be passed off from infected clippers or other instruments. Be very fussy about the instruments that are being used on your feet. If in doubt, go ahead and bring your own sterilized set, and insist that they use those.
If prevention does not succeed in warding off a fungal infection, know that there are several good options for toenail fungus treatment, ranging from oral and topical agents to surgical procedures for the most severe of cases.