shlinkio / shlink

The definitive self-hosted URL shortener
https://shlink.io
MIT License
3.35k stars 275 forks source link

Config option to ignore extra paths #2265

Open sutterseba opened 1 week ago

sutterseba commented 1 week ago

Summary

Currently, there is a config option "Append extra path", which will append extra paths in the URI to the destination, e.g. /example/blah will forward to destination.com/blah.

A similar config option that does not append additional paths to the destination and instead ignores them would be great and should be quite simple to implement.

short.com/example                -> destination.com
short.com/example/blah           -> destination.com
short.com/example/blah/blah/blah -> destination.com

Use case

This would generally allow distinguishing URLs from each other outside the native tracking/tagging solutions. In my case, I have a lot of old URLs with lots of different additional paths (due to how our old URL shortener worked) which would currently all break with Shlink.

acelaya commented 4 days ago

Yeah, I think this shouldn't be super hard to do.

As you noted, there's currently a configuration option to tell if the extra path should be appended when redirecting. This option accepts true and false values.

I would probably deprecate this option and replace it with a more flexible one that accepts a set of values that would determine how to match short URLs when an extra path is found:

The last two options would be handled in ExtraPathRedirectMiddleware, ignoring the $extraPath if the option is configured as ignore.