What do you have set in the WordPress admin under Settings -> General and then WordPress Address
and Site Address
? Make sure these are both using the www.example.com
domain.
If you want to use an htaccess
rule, which will run before WordPress kicks in, there are plenty of answers on StakOverflow such as this one: https://stackoverflow.com/questions/4916222/htaccess-how-to-force-www-in-a-generic-way