Images not working after updating the WordPress URL

April 1, 2013 by: Sudheer

You may have installed your wordpress to different URL something like http://example.com/wordpress and now you want to change it http://example.com . You have update the Site URL and Home URL (click here for more details) and pointed the domain to the folder. Your website is working fine and you are able to access the wordpress dashboard. However, you are not able to access the images now. The image path are loading with the old path like http://example.com/wordpress/uploads/2013/01/01/image.jpg with the 404 error. How it can be fixed?

The images are not loading because the image path is set to http://example.com/wordpress in all the posts. You have replace the old path with the path. You can do it using the plugin ‘Search and Replace‘.

If you do not wish to use the plugin, you can run the below MYSQL query to change the path in the posts and other tables where the path is set to old URL http://example.com/wordpress .

update wp_options set option_value=replace(option_value,'http://example.com/wordpress','http://example.com') where option_value like "%http://example.com/wordpress%";
update wp_posts SET guid=replace(guid, 'http://example.com/wordpress','http://example.com');
update wp_posts SET post_excerpt=replace(post_excerpt, 'http://example.com/wordpress','http://example.com');
update wp_posts SET post_content=replace(post_content, 'http://example.com/wordpress','http://example.com');
update wp_postmeta SET meta_value=replace(meta_value, 'http://example.com/wordpress','http://example.com');

It will replace all the fields which contains http://example.com/wordpress to http://example.com .

Filed under: WordPress

Leave a Reply