Wordpress从图片网址中删除“www”

I have website developed by wordpress and I'm facing the issue was image not co-ordinate with url.

the image url Should be ...

http://domainname.com/wp-content/uploads/2012/09/handshake-cropped-300x2651.png 

but am getting with "www" ie :

http://www.domainname.com/wp-content/uploads/2012/09/handshake-cropped-300x2651.png 

so the reason image not loading to my site, I checked in media library for the image url...

What is the reason for this issue? and how can I fixed this. Even I have changes upload path url and site url too :(

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]

OR

# force non-www domain
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]

You can create a CNAME record in your DNS that maps the www domain to the main domain. Go to your DNS manager and add a www. record pointing to @ or your domain IP

You also need to add an alias in your apache config.

ServerAdmin me@mymail.com
ServerName example.com
ServerAlias www.example.com

There is scope of improvement in this. But let me know if this works.

add_filter( 'the_content', 'attachment_image_link_remove_filter' );

function attachment_image_link_remove_filter( $html ) {
  return str_replace('<img src="http://www.','<img src="http://',$html );
}


add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );

function my_post_image_html( $html, $post_id, $post_image_id ) {
  return str_replace('http://www.','http://',$html);
}

add this code in your functions.php