Solution:1
You can probably use something like the following in your .htaccess
:
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/
RewriteRule ^(.*)\.(jpe?g|gif|png|bmp)$ https://example.com/wp-content/uploads/$1\.$2 [NC,L,R=302]
Solution:1
You can probably use something like the following in your .htaccess
:
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/
RewriteRule ^(.*)\.(jpe?g|gif|png|bmp)$ https://example.com/wp-content/uploads/$1\.$2 [NC,L,R=302]
Solution:2
Immediately after the RewriteEngine On
line try the following:
RewriteRule ^images/(\d+)/image(\d)\.(png|jpg)$ /images/$10$2.$3 [R=301,L]
RewriteRule ^images/(\d+)/image(\d{2,})\.(png|jpg)$ /images/$1$2.$3 [R=301,L]
The first rule handles the image names that contain a single digit (that must be prefixed with 0
) and the second rule handles the rest.
The $1
, $2
and $3
backreferences match the corresponding capturing subgroups in the preceding RewriteRule
pattern. In other words, $1
contains the folder name (all digits), $2
contains the number that appears after the filename and $3
contains the file extension (either jpg
or png
).
NB: Test first with 302 (temporary) redirects to avoid potential caching issues.
To clarify, presumably you are already linking to the new image URLs internally?