0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
RubenHerman
  • 1,674
  • 6
  • 23
  • 42

1 Answers1

1
UPDATE TABLE SET MyUrl = replace(MyUrl, '/?', '?') WHERE MyUrl like '%/?%';

Working SQLFiddle

TheWildHealer
  • 1,546
  • 1
  • 15
  • 26