skybrud / Skybrud.Umbraco.Redirects

Redirects manager for Umbraco.
https://packages.limbo.works/skybrud.umbraco.redirects/
MIT License
36 stars 41 forks source link

Supporting wildcards with * #203

Open Matthew-Wise opened 1 month ago

Matthew-Wise commented 1 month ago

Which version of Skybrud Redirects are you using? (Please write the exact version, example: 4.0.8)

-

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

10+

Question

Being able to do /* for all children is something we have found useful when doing redirects in code before. Looking at the redirect service, I think swapping it out for a % in the SQL query would be enough, and maybe a UI checkbox for it?

Let me know what you think happy to look at doing a PR for the feature

Thanks Matt

abjerner commented 1 month ago

Hi @Matthew-Wise

I'm not entirely sure this is such a good idea from a technical point - e.g. due to the potential impact in may have on performance, and the extra complexity it will add to the package.

So instead of creating the PR right away, perhaps let's continue the discussion here first. For instance, I'd like to see the SQL for looking up wildcard redirects. I don't think it will be a as simple as replacing a * with a %.

Matthew-Wise commented 1 month ago

Been thinking about this more as well and your right.

I think we could solve this by having a "include descendants" options in the UI which maps to a bool in SQL.

We could then split the path into segments and query for the full path or the split paths that Include descendants. order by url length so you get the deepest match

------------------ A very rough SQL example (this schema was taken for a v8 project for speed) ------------------

begin tran

declare @SkybrudRedirects TABLE ( [Id] [int] IDENTITY(1,1) NOT NULL, [Key] [uniqueidentifier] NOT NULL, [RootId] [int] NOT NULL, [RootKey] [uniqueidentifier] NOT NULL, [Url] nvarchar NOT NULL, [QueryString] nvarchar NOT NULL, [DestinationType] nvarchar NOT NULL, [DestinationId] [int] NOT NULL, [DestinationKey] [uniqueidentifier] NOT NULL, [DestinationUrl] nvarchar NOT NULL, [Created] [datetime] NOT NULL, [Updated] [datetime] NOT NULL, [IsPermanent] [bit] NOT NULL, [ForwardQueryString] [bit] NOT NULL, [DestinationQuery] nvarchar NOT NULL, [DestinationFragment] nvarchar NOT NULL, [IncludeDescedents] [bit] NOT NULL )

insert into @SkybrudRedirects values (NEWID(), 0,NEWID(), '/example','','content',1000,NEWID(),'/', GETDATE(),GETDATE(),1,1,'','',1)

insert into @SkybrudRedirects values (NEWID(), 0,NEWID(), '/example/unquie/result','','content',1000,NEWID(),'/', GETDATE(),GETDATE(),1,1,'','',0)

-- Requested path /example/global

select * from @SkybrudRedirects where [url] = '/example/global' or ([url] = '/example' and IncludeDescedents = 1)

-- Requested path /example/unquie/result

select * from @SkybrudRedirects where [url] = '/example/unquie/result' or ([url] = '/example/unquie/' and IncludeDescedents = 1) or ([url] = '/example' and IncludeDescedents = 1) order by IncludeDescedents, len([Url]) desc

rollback tran