Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • mattou07 15 posts 109 karma points MVP 2x c-trib
    Dec 16, 2016 @ 12:00
    mattou07
    0

    Injecting mass amounts of redirects using SQL into Url Tracker

    I have around 600 entries I need to add to Url Tracker.

    I had a go at creating my own script to convert all the entries into SQL queries to query to the Url tracker table.

    Here are some samples of SQL generated:

    INSERT INTO [dbo].[icUrlTracker] (OldUrl,OldUrlQueryString,RedirectRootNodeId,RedirectNodeId, RedirectHttpCode, RedirectPassThroughQueryString, Is404,Inserted,ForceRedirect) VALUES('/charging-information.cfm','id=180&sub',1064, 1064, 301,0,0,getDate(),0)
    
    INSERT INTO [dbo].[icUrlTracker] (OldUrl, RedirectRootNodeId,RedirectNodeId, RedirectHttpCode, RedirectPassThroughQueryString, Is404,Inserted,ForceRedirect) VALUES('/mobile/', 1064, 1064, 301,0,0,getDate(),0)
    
    INSERT INTO [dbo].[icUrlTracker] (OldUrl, RedirectRootNodeId,RedirectUrl, RedirectHttpCode, RedirectPassThroughQueryString, Is404,Inserted,ForceRedirect) VALUES('/legacy/article/1149', 1064, '/news-insight/', 301,0,0,getDate(),0)
    

    Once I enter those links in, I attempt to test to see if they return 404's. Most of the 600 links fail. However if I go to the back office and find a link in Url Tracker and re save it. It works and does a 301 redirect. I can't see any changes in the SQL.

  • mattou07 15 posts 109 karma points MVP 2x c-trib
    Dec 16, 2016 @ 13:25
    mattou07
    0

    Discovered this was happening because the URL's begin with a slash.

    INSERT INTO [dbo].[icUrlTracker] (OldUrl,OldUrlQueryString,RedirectRootNodeId,RedirectNodeId, RedirectHttpCode, RedirectPassThroughQueryString, Is404,Inserted,ForceRedirect) VALUES('charging-information.cfm','id=180&sub',1064, 1064, 301,0,0,getDate(),0)
    

    Removing the slash at the start fixes the issue.

    Hope this helps others.

Please Sign in or register to post replies

Write your reply to:

Draft