Title: Images within a post display fine but clicking on images return 404 not found error
Tags: wordpress;http-status-code-404;permalinks
Question: To start with, I am not an expert of any kind. Codes drive me insane. I run a site called: http://nascentarray.com.

I moved the site from one host to another and after the migration, I found that many images were broken. So, I changed the permalink structure:

From: nascentarray.com/post-name/
To: nascentarray.com/year/month/date/post-name/

Everything looked fine until I started getting 404 errors on images interested into the posts directly.

To me more specific, I use two methods to insert images:


I use the Jetpack module of WP to create a gallery in mosaic layout that gives a carousel of images when someone clicks on the gallery.
For some posts, using Jetpack gallery module makes no sense and so, I simple insert individual images between texts using the simple media uploader.


Problem: The problem is with the posts where I do not use the Jetpack gallery module. When I click on a post, the post opens fine and shows all images in it. However, the moment I start clicking on individual images, they start giving 404 error.

Example: http://nascentarray.com/2013/02/08/tallest-buildings-of-2013/

Clicking on any image in the post will return a 404 error.

How to solve this problem? Anyone, please help me. This is so disturbing and I don't have enough technical expertise to deal with this on my own and so I can came here with a hope to find some help from experts.


Here is the accepted answer: The posts where you don't use jetpack image gallery module doesn't embed a gallery. Instead, you embed images in your posts individually. When you embed, there's option with image link whether you want to link image with post, attachment page, custom link or source file. 
Your images are not linked to source file - instead those are linked to POST ATTACHMENT link. 

Once you changed the permalinks structure of your post, the links associated with your image files were not updated and those remained as per previous permalink structure those don't exist now and thus it gives 404 error. 

It's solution can be to revert your permalinks structure to previous one (short and immediate solution) and other solution can be writing a short script and update all links of images in batch with their source file or anything else.

Another solution is to use Yoast SEO plugin to generate redirect URL's for old backlinks. 
See the guide in this blog post regarding this solution.

I hope this helps and you understand the issue now.

Comment for this answer: Thanks for appreciation. Please ACCEPT my answer by clicking TICK sign and VOTE for my answer. In case you need any further help, let me know. But don't forget to accept my answer and i will VOTE for your question as well that will increase your reputation points. @user2513375
Comment for this answer: Thanks. You first click "Arrow UP" icon that's on left side of answer, that's above score (here score is 1 at the moment) for VOTING UP & then click the TICK icon. Thanks.
Comment for this answer: That was awesome! I will give the last option a try once I move to new host. My current host godaddy has a weird restriction that they never mentioned when I bought a hosting plan with them. They do not allow more than 1024 files in a single folder and it should be preferably below 1000. They also do not allow more than 500,000 files in entire windows or linux hosting even if you have unlimited space. That is the most ridiculous thing I have ever heard of.
Comment for this answer: Sorry, just went back to my website and didn't notice your reply. How do I accept and vote. I am new here. I don't know how to do so. Will you mind guiding me again?
Comment for this answer: I think I just figured out and did it :)

Here is another answer: Your permalink structure is incorrect. You need to change it back to nascentarray.com/year/month/date/post-name/

If it's already that way, then you need to double check your folders in uploads. Because if you look at your one page here http://nascentarray.com/2013/06/17/stock-wallet-the-only-wallet-you-will-ever-need/

That image is linked with ../year/month/date/post_name/image_name/
i.e. http://i0.wp.com/nascentarray.com/wp-content/uploads/2013/06/stock_wallet_2.jpg?resize=389%2C176

Obviously your plugin for viewing galleries adds the extra stuff in the URL's.

Where as the link you gave above has just ../post_name/image_name/ Which isn't working with your plugin or linking of the image file.

Comment for this answer: Thank you for the reply. I think, the other person has given be a nice solution. I may just try that once.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:06/23/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<wordpress><http-status-code-404><permalinks>', 'Title': 'Images within a post display fine but clicking on images return 404 not found error', 'ViewCount': 2228, 'id': 17259918, 'user_AboutMe': None, 'user_AccountId': 2933933.0, 'user_DisplayName': 'user2513375', 'user_Reputation': 23.0, 'user_Views': 6.0, 'user_id': 2513375.0}}