There are two answers to that question, actually three!
How to prevent ads and pop-ups: Download and install GlimmerBlocker: http://glimmerblocker.org/
How to prevent re-direction:
Adding Open DNS codes to your Network Preferences, should give good results in terms of speed-up as well as added security, (including anti-phishing and redirects) (Full information about Open DNS is here: http://www.opendns.com/home/nobloat ) and further independent information can be read here:
Open System Preferences/Network. Double click on your connection type, or select it in the drop-down menu, and in the box marked 'DNS Servers' add the following two numbers:
(You can also enter them if you click on Advanced and then DNS)
There are many forms of ‘Malware’ that can affect a computer system, of which ‘a virus’ is but one type, ‘trojans’ another. Using the strict definition of a computer virus, no viruses that can attack OS X have so far been detected 'in the wild', i.e. in anything other than laboratory conditions. The same is not true of other forms of malware, such as Trojans. Whilst it is a fairly safe bet that your Mac will NOT be infected by a virus, it may have other security-related problem, but more likely a technical problem unrelated to any malware threat.
You may find this User Tip on Viruses, Trojan Detection and Removal, as well as general Internet Security and Privacy, useful:
The User Tip (which you are welcome to print out and retain for future reference) seeks to offer guidance on the main security threats and how to avoid them.
You have probably downloaded and installed some junky software that adds a plugin to your web browser, but there are some other possibilities as well. See: