I need help with a regex redirect.
I have a working regex
'^page\.php\?t=(\d+)$' => 'page/t-$1/'
to redirect
/page.php?t=123 > /page/t-123/
I need regex to redirect
/page.php?t=123/dynamic-text-123/ > /page/t-123/dynamic-text-123/
You effectively only need to remove the .php?t= portion.
Since it seems that you are comfortable hardcoding the leading page component, you only need to match the trailing t value with a lazy wildcard (.*?) and exclude the optional trailing / then append that captured value to page/t-, then apend a slash at the end like so:
'^page\.php\?t=(.*?)/?$' => 'page/t-$1/'
I am making the trailing / match optional, since it is not always there yet it seems you want the / in the replacement no matter what.
/? when the greedy .* already matches it?/ at the end, but in the second sample input, it is present at the end. The desired replacement always wants the / at the end, so I am hardcoding it into the replacement and omitting it from the capture group.
^page\.php\?t=(\d+)\$u=\/(?:\w+-)+\d+$^page\.php\?t=(.*)$