Welcome Guest, Not a member yet? Register   Sign In
$routes->addRedirect with regex?
#1

I'm trying to deprecate the use of .html suffixes for my urls. I'm trying to redirect old urls like this:
Code:
https://www.example.com/subdir/some-item-title/page-specifier-15-1132.00.html
to the new identical URL but minus the .html at the end:
Code:
https://www.example.com/subdir/some-item-title/page-specifier-15-1132.00

NOTE: the some-item-title and page-specifier change and can be almost anything depending on the item. I added this addRedirect line to my Config/Routes.php file:
PHP Code:
$routes->addRedirect('subdir/([a-z\-]+)/([a-z\-]+)-(\d{2}-\d{4}\.\d{2})\.html''subdir/$1/$2-$3'); 
However, the addRedirect function apparently doesn't work with the backreferences. I do get a redirect but, rather than containing the patterns matched in the original url, the new url just has literally $1, $2, and $3:
Code:
https://www.example.com/subdir/$1/$2-$3

Does addRedirect not support backreferences? If so, it might be helpful to clarify this in the documentation. How should I go about solving this problem? NOTE: I do *not* want to redirect all urls ending in .html.
Reply


Messages In This Thread
$routes->addRedirect with regex? - by sneakyimp - 02-10-2021, 05:31 PM
RE: $routes->addRedirect with regex? - by iRedds - 02-11-2021, 03:37 AM
RE: $routes->addRedirect with regex? - by iRedds - 02-11-2021, 11:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB