I have table with 2 columns where in one of them an url is stored.
Now I would need to update the table to remove all trailing slashes from the urls, including urls that have a query string.
Examples:
/page/sub/1/ => /page/sub/1 /page/sub/1/?page=1 => /page/sub/1?page=1
I’ve found how to do it for a trailing slash, but not when it’s inside the url.
UPDATE TABLE SET MyUrl = LEFT(MyUrl, LEN(MyUrl) - 1) WHERE RIGHT(MyUrl, 1) = '/';
Does anyone have an idea how to do this? Can I use a regex of some kind?
Advertisement
Answer
UPDATE TABLE SET MyUrl = replace(MyUrl, '/?', '?') WHERE MyUrl like '%/?%';