Why does Shlink ignore the domain parameter if it's the DEFAULT_DOMAIN? #2367
-
Shlink versionlatest available PHP versionHow do you serve ShlinkDocker image Database engineMariaDB Database versionlatest available SummaryI used to use shlink with the BASE_DOMAIN example.com. I created a lot of shorturls but always by setting the domain parameter when talking to the API. Now I added another shorturl domain example.io and this should become the new DEFAULT_DOMAIN. But of course I want the old shorturls that I actively set to be used by example.com to still be used by that domain and not the new DEFAULT_DOMAIN. Why do you ignore the domain parameter when it matches the default domain? A user who sets the domain parameter needs to be sure that the system will actually set that domain in the database and not ignore it. If I wanted those short urls to dynamically match the current DEFAULT_DOMAIN I wouldn't have set the domain parameter. I now had to change all entries in my database manually. :/ |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is mainly due to backwards compatibility and historical reasons. In the beginning, Shlink did not support multiple domains explicitly, but you could of course have a single Shlink instance and point multiple domains at it, which means every existing short URL would work for all those domains. In order to avoid breaking existing instances, Shlink introduced support for multiple domains in a way that the default domain would be identified by the lack of a explicitly set domain. There have been some previous discussions about this behavior: #1535 I even considered changing this behavior (I would probably not implement it like this today) #1536, but the issue did not have any attention. Considering the relatively high complexity of doing this change, plus the chances of messing something up, I ended up closing that issue.
Well, that's certainly one possibility, although I would not assume that's what every Shlink user would want. One certainly feasible possibility would be for Shlink to provide mechanisms to change the default domain, allowing you to explicitly "move" existing default-domain short URLs to the previous default domain if desired, and even making non-default-domain short URLs become the default if the new DEFAULT_DOMAIN was previously known by Shlink as a non-default. Doing this manually is pretty easy anyway: -- Create a new domain for your previous domain ID
INSERT INTO domains SET authority='your_previous_default_domain';
SET @new_domain_id = LAST_INSERT_ID();
-- Update all short URLs previously linked to the default domain, to be linked to the new domain
UPDATE short_urls SET domain_id=@new_domain_id WHERE domain_id IS NULL; So Shlink could provide this behavior via a console command. |
Beta Was this translation helpful? Give feedback.
This is mainly due to backwards compatibility and historical reasons.
In the beginning, Shlink did not support multiple domains explicitly, but you could of course have a single Shlink instance and point multiple domains at it, which means every existing short URL would work for all those domains.
In order to avoid breaking existing instances, Shlink introduced support for multiple domains in a way that the default domain would be identified by the lack of a explicitly set domain.
There have been some previous discussions about this behavior: #1535
I even considered changing this behavior (I would probably not implement it like this today) #1536, but the issue did not have any attention. …