How to rewrite URLs of images .htaccess?

Good morning dear hackers.
Never worked with the file .htaccess
I want to convert links to images .
here are links for example
https://oldsite.ru/mugs/Flagler/2018/2018-00001170.jpg
https://oldsite.ru/thumbs/Flagler/2018/2018-00001170.jpg

such
https://newsite.ru/Eachtime/Flagler/mugshots/2018/2018-00001170.jpg
https://newsite.ru/Eachtime/Flagler/thumbnails/2018/2018-00001170.jpg

this directory may not be /2018/ or it may be 2017
/Flagler/ this part can vary depending on the categories

It seems to have the opinion that you can do through the regular season. But I wrote earlier this year in php functions such as preg_match .
But how this is done in htaccess please?
And if you do not complicate the regexp would also like to see basic design below then its finished
June 5th 19 at 21:27
1 answer
June 5th 19 at 21:29
Solution
Actually this is pregmatch
RewriteCond %{HTTP_HOST} ^oldsite\.ru$
RewriteRule ^mugs/(.+[^/])/([0-9]{4,}/2018\-00001170\.jpg)$ https://newsite.ru/Eachtime/$1/mugshots/$2? [L,R=301]

Let's order.
RewriteCond %{HTTP_HOST} ^oldsite\.ru$
If such a domain (can be omitted as will be spelled out on this site, so you can delete)
(.+[^/])/ any number of characters from 1 to infinity in addition / to /, in General, allocated all until the next slash.
Well obyedinyaet all this happiness in the first group ()
Do the same with the date
[0-9]{4,} from zero to nine 4 times, and obyedinyaet already a large enough part of the url the second group.
Actually substitute the selected group to place the new url $1 and $2
The last step, go to the toaster click solved ;)

ps
Can competently would be to take the first group through greedy and lazy quantifiers but as practice shows people do not catch up that it is, in General, will work and so ;)
Thank you . You can write to me on Skype.
nurbek.dildabekov want to offer you this job - Octavia_Moore commented on June 5th 19 at 21:32
shambler81 - Lavern_Schuppe commented on June 5th 19 at 21:35

Find more questions by tags htaccessProcessing URL