Answer the question
In order to leave comments, you need to log in
How to redirect via htaccess to a new URL while keeping part of the old one?
Good evening everyone!
There is an online store, several thousand products.
At the moment, the goods have approximately the following addresses
https://site.ru/category1/subcategory34/good1234
https://site.ru/category1/good1234
The example implies that the same product can have several addresses, because may be in multiple categories.
There is a task to rename the last part of the url related to the product in the CNC
. it should look something like this
https://site.ru/category1/subcategory34/zerkalo-na...
https://site.ru/category1/zerkalo-nastennoe
Everything would be fine, but after this renaming, you need to load the redirect map into .htaccess , which needs to be generated knowing the old part of the url and the new one.
Those. we have good1234 and zerkalo-nastennoe and we need a rule that will make a 301 redirect from
*
/good1234 to */zerkalo-nastennoe keeping the path up to the last slash from the entered url
well, there is something generally plugging, I could not find anything working, the condition does not work stupidly.
Here is one example
RewriteRule ^(.*)/$good1234 $1/zerkalo-nastennoe [R=301,L]
RewriteRule category1/subcategory34/good1234/(.*)$ category1/subcategory34/zerkalo-nastennoe/$1 [R=301,L]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question