Foe example. Lets take 4 URLs (existing or future) that follow the targeted pattern of:
https://KeepThisPartTill-cde.com/a/b/cde/ThisWillBeDifferent/ThisWillNot
https://KeepThisPartTill-cde.com/a/b/cde/ThisIsDifferent/ThisWillNot
https://KeepThisPartTill-cde.com/a/b/cde/ChangedAgain/ThisWillNot
https://KeepThisPartTill-cde.com/a/b/cde/AndAgain/ThisWillNot
So. If any of these (existing or future) links is clicked, we need them to be changed to:
https://KeepThisPartTill-cde.com/a/b/cde/WhateverThisWillBe/ThisWillNot?SomethingHere
This means:
If one clicks on a link that starts with https://KeepThisPartTill-cde.com/a/b/cde/
, keep this part, add the part WhateverThisWillBe
(which extends until you find the next /
), add /ThisWillNot?
(notice the ?
) and finally add SomethingHere
Should I probably be using .htaccess
Please keep in mind that although it is about a WordPress site, I can figure the SomethingHere
which is WordPress related but have a difficult time figuring out how to keep the first part intact when the second WhateverThisWillBe
part is different (in every single link) and add /ThisWillNot?
after it.
Using preg_replace: