0

I have lots of image files without an extension (no .png, .jpg, .etc) in the Wordpress uploads folder (/wp-content/uploads/2024/). These do appear in articles and are used, but due to the missing extension they're not cached and I suppose they hurt SEO a little too. Besides, not having an extension, browser tend to download them, not display them.

My question is, how to rewrite these URLs so that the site.com/wp-content/uploads/2024/image will load in the browser like this /wp-content/uploads/2024/image.jpg? To make things worse, there are also image that have only the DOT (.) at the end, without the extension, and all these are mixed together with the valid one, images with .jpg, .png, . webp. In a word, mess.

While ideally changing the database and the adding the file extension should be preferred, it is not something easily done. So I'd rather use a rewrite rule to keep things simple and doable.

The /wp-content/uploads/2024/ has only images, so I'm thinking of 2 rewrite rules, but cannot put them on paper: one to check if the file doesn't have an extension, then the rule another to check if the file end in (.), then rewrite

Please help

4
  • If all the images are only JPG or only PNG, then this is a solvable issue. However, if there are many kinds of images, then you are out of luck. nginx decides the MIME type of the image based on the file extension. So, for .jpg / .jpeg, nginx sends MIME type for JPEG image. I would always take the effort to fix this properly. Adding such a redirect layer will only make the setup more unstable. Commented Mar 5, 2024 at 16:15
  • I think you misread my issue. Basically, I have image1, image2. and image3.png in a folder, and I'm looking for a way to visit site.com/image1.png and site.com/image2.png and the browser to display image1 and image2. in stead. Commented Mar 8, 2024 at 19:49
  • Sorry, but this looks still a bit confusing. Could you give explicit example, where you have: A) Filename of the file as it exists on the filesystem B) Full URL that you want user to enter to see the file. Commented Mar 9, 2024 at 2:34
  • try_files could do a thing, but imho it will be nearly impossible to set the correct ending Commented Mar 12, 2024 at 20:10

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.