Set alternate domain for tinyurls?

By default Kirby has tinyurls, and I can display those just fine. What I would like to do is have them generated with an alternate, shorter domain name than the standard one for the website. Is there a config for this?

My alternate solution will be to use PHP to parse out the path from $page->tinyurl() and add my own domain to the front of it, but if there’s a config that would be cleaner.

You should be able to set the tinyurl.folder option to an absolute URL:

c::set('tinyurl.folder', 'https://sho.rt');
1 Like

Excellent. Kind of obvious in retrospect. Thanks! Works like a charm.

I have just looked into the Kirby code and actually it can’t really work right now. The link is generated just fine, but if you visit the generated URL, Kirby will not correctly route it. Or does it really work for you?
If not, I will fix it in Kirby 2.4.

Ah, dangit. No, it doesn’t work. 404

What kind of setup are you using? Does the short domain point to your site as well or do you use some kind of redirection or third-party service there? I’m asking because I’m trying to find out which kind of implementation would be best.

For this I was just doing a local test where the local “short” domain was an alias for the local “long” domain. In actual implementation, I would probably redirect the short URL first to make sure someone doesn’t get shorturl.com/final-url instead of longurl.com/final-url. I would do that in htaccess on the server, though.

Yes, that’s what I’d prefer as well. What do you think of an option like that:

c::set('tinyurl.folder.out', 'https://sho.rt');

It would only apply to the link generation but Kirby would still expect incoming requests in tinyurl.folder (/x by default). We just need a better name for the new option. :wink:

Yeah, something like that would be fine. I just want to be able to generate it with a different domain name, although having it automatically redirect to the canonical domain name as part of the standard shorturl redirect would be gravy.

That’s unfortunately not going to work as Kirby does not know the “real”/long domain to redirect to.

That can’t be true, since it uses it for all generated URLs. I’m thinking what’s set in c::set('url')

Well, if you visit https://sho.rt/x/tinyurl, Kirby will use https://sho.rt as base URL, not your actual long one. It would work with the url option, but it is not required and I think we shouldn’t make it required. It’s better to do the redirection in the .htaccess, that’s more reliable.

That’s fine. Although maybe while you’re adding an option to choose your shorturl domain, you could include the ability to set the redirect domain as well?

What do you mean with redirect domain?

I mean like you have the shorturl domain, and then a config to let kirby know if you want to use a different domain name when expanding that.

This is now implemented for Kirby 2.4. See the documentation for more details.

1 Like