0

Is there a way to export all redirect maps via a PowerShell script or a simple GUI in Sitecore that I am missing? I want a list of them all - don't care about the formatting as long as I can make sense of it.

I have 3 Redirect Map Groupings and redirects under those. I simply would like to export everything under Sitecore's main Redirects group.

The setup is as described here - https://doc.sitecore.com/xp/en/users/sxa/102/sitecore-experience-accelerator/map-a-url-redirect.html

Is this possible without a heavy lift, installing something, and/or going one by one copying out the raw values for each?

2 Answers 2

1

Here is a basic example at how you can take a known root ID of "Redirects" and output all of the mappings.

$redirectsRootId = "{CE4886A6-0372-42FB-B27E-B1E417A4A2F2}"
$redirectMaps = Get-ChildItem -Path "master:" -ID $redirectsRootId | Where-Object { $_.TemplateID -eq "{F4FB6125-F113-4373-8AA2-4648C2C1960E}" }
$records = [System.Collections.ArrayList]@()
foreach($redirectMap in $redirectMaps) {
    $nameValues = [System.Web.HttpUtility]::ParseQueryString($redirectMap.UrlMapping)
    foreach($key in $nameValues.AllKeys) {
        $record = [PSCustomObject]@{
            "Old" = $key
            "New" = $nameValues[$key]
        }
        $records.Add($record) > $null
    }
}

$records | Show-ListView

Sample Report

References

2
  • That generally worked. When I go to the redirect group parent of the redirects. So thank you for that, but is there a way to use the grandparent? The way Sitecore recommends (and our current setup) is in the content editor under the tree of "Setting" > there is a "Redirects" node and under that node are all the redirect groups and under the redirect groups are the redirects. So Settings > Redirects > (a bunch different groups) > the targets. I can get the id of the grandparent "Redirects", but when I run the script at that level nothing is returned. Feb 3 at 17:09
  • You can add -Recurse to the call to Get-ChildItem if you use nested folders. You can also do more filtering and add columns if you need to distinguish between which RedirectMap is being shown. So many options! Feb 3 at 17:15
0

This is not the PowerShell script way you are looking for. Just a workaround, I used to fetch all the redirect URLs under Redirect Map Groupings.

  • Click on the redirect map item and check raw values from the view tab.
  • Grab the complete string from the field Mapping between old and new URL paths and paste this string into the editor (notepad++). You can replace & with the new line.
  • Now you will have the complete list in format source URL=target URL.You can further take this list to excel and split it with =

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.