Score:0

RegEx for 301 redirects to change path AND remove a string

tg flag

I am looking for an RegEX redirect rule to redirect the image file locations to a new location, whilst also removing part of the original url which is the name of the image

OLD URL:

/components/com_mijoshop/opencart/image/cache/catalog/ecom2/GM815-365x365.jpg

NEW URL:

/wp-content/uploads/nc/catalog/ecom2/GM815.jpg

So I need to change the directory path AND remove the ‘-365x365’ part of the url.

I can remove the part of the image name with the following, but unsure how to also change the path:

/(?'path'.*)-365x365.jpg  /[path].jpg
us flag
What is the environment where you are using the regex?
Rebecca Hubbard avatar
tg flag
It’s Wordpress, a redirect plugin. We migrated from a really old Joomla site and we have thousands of image urls that have changed that I would like to put 301s on.
us flag
Please add link to the plugin to the question, so that we can check the documentation. Without seeing documentation, an answer cannot be given.
Rebecca Hubbard avatar
tg flag
Please see link to the plugin documentation. If you could help it would be very much appreciated. https://docs.wp301redirects.com/article/307-regex-redirects-recipes
Score:0
us flag

You can try this:

/components/com_mijoshop/opencart/image/cache/(?'path'.*)-365x365.jpg /wp-content/uploads/nc/[path].jpg
Rebecca Hubbard avatar
tg flag
Thanks so much, that worked perfectly!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.