Short URLs
When using twitter, or other mobile devices where space is a premium, it is quite common to use shortened URLs. Many people will not be keen on typing http://www.openstreetmap.org/?lat=51.5073&lon=-0.1278&zoom=14&layers=M, and will prefer something like http://osm.org/go/euu4gY@w- instead 1.
The URLs for my articles are automatically generated from the title. There is a little function that uses translit's transliterate() function to ASCII-ify the titles. It transforms for example "pfcongrez, P2P Конференция, php|tek, PHP Vikinger, DPC and eZ Conference and Awards" to "pfcongrez-p2p-konferenciya-phptek-php-vikinger-dpc-and-ez-conference-and-awards" with code similar to:
$titleShort = transliterate( $fullTitle,
array(
'cyrillic_transliterate', 'lowercase_latin',
'normalize_ligature', 'diacritical_remove',
'normalize_punctuation', 'remove_punctuation',
'spaces_to_underscore', 'compact_underscores'
),
'utf8', 'us-ascii'
);
However, http://derickrethans.nl/pfcongrez-p2p-konferenciya-phptek-php-vikinger-dpc-and-ez-conference-and-awards.html is hardly a short URL. What we want is something short and descriptive. First of all, I thought it would work to generate short URLs automatically, following the following algorithm:
-
Strip out all chars that are not
A-Z,a-z,0-9,., space and-. -
Split the title up in words, splitting on space.
-
If the sanitized URL is shorter than 14 chars: join the words back together with a "-", otherwise:
-
Loop over each word, replacing each word with the first letter of the word, unless it is one of the important words (such as "php" or "xdebug").
-
Add a marker for the date, to ensure that short URLs are unique. The date marker is generated like:
-
Format the date as
two digit year,ISO weekandISO weekday -
Convert the created number to base 36 with:
php -r "echo date_create( '20090410' )->format( 'yWN' );" 09155 php -r 'echo base_convert("09155", 10, 36), "\n";' 72b -
Our long title from above, then turns into pp-p-php-vdaecaa-72b. Although relatively short, it is still not a descriptive URL. To be honest, it's a bit difficult to come up with a short, descriptive URL for this title, so let us examine another one, of a more recent post.
The title "64-bit integers in MongoDB" is converted into "6iim-7yp", which is again short, but not very informative; and "Xdebug 2.1 Released" is converted into "xdebug-2.1-7x2", which does make sense.
Because I did not get very good results with automatically converting titles into sort URLs, I decided that for all new articles I will just define my own.
Now, once we have the short URLs, they need to be used. Instead of my long main domain http://derickrethans.nl, I registered a new one just for short URLs: https://drck.me to reduce the URL length even more. For the current article, the length of the URL shrinks from 39 to 26 characters. The short URL is also embedded in the HTML source with a rev=canonical tag and a rel=shortlink tag, such as:
<link rev="canonical" type="text/html" href="https://drck.me/shrturl-8ju"> <link rel="shortlink" type="text/html" href="https://drck.me/shrturl-8ju">
This tag is meant to provide alternative URLs for the current one. For more information on rev=canonical see http://revcanonical.appspot.com/ or Chris Shiflett's entry, and for rel=shortlink see the microformats site. The shortlink specification also recommends the use of the HTTP Link: header:
Link: <https://drck.me/shrturl-8ju>; rel=shortlink
The two tags and the HTTP header make it possible for services that prefer an as short as possible URL to automatically discover a shorter version. Sadly, it doesn't see that the twitter home page does this. I hope they will add support for that in the future. From my side, I am going to implement this in Haunt, my twitter client build in PHP-GTK.
Comments
I made an extension for Habari the other week that does this, but it embeds it in the source using link rel="shortlink" instead, which based on my research at the time was the way forward. I might be wrong, though!
@Michael: Thanks! I was not aware of that. I've added both rel=shortlink and the Link: HTTP header to the post, as well as to the software running this website.
-
1
This actually uses a very clever form of shortening geo-locations: http://wiki.openstreetmap.org/wiki/Shortlink
Life Line
I've finished reading Children of Memory, the third book in the series.
Another interesting take on forms of intelligent life.
A fourth one is going to get released later this year.
Updated a post_box, a beauty shop, and a restaurant; Confirmed 2 clothes shops, 2 pet shops, and a restaurant
I walked 5.9km in 1h40m39s
Updated a bicycle_parking
Updated 2 waste_baskets
I walked 7.9km in 1h37m12s
Created 3 waste_baskets; Updated 3 bus_stops, 2 benches, and 2 waste_baskets
I walked 8.1km in 1h25m53s
I walked 1.2km in 9m31s
I walked 9.4km in 1h39m05s
Merge branch 'xdebug_3_5'
Merged pull request #1071
Fixed issue #2411: Native Path Mapping is not applied to the initial …
Created 2 waste_baskets; Updated 3 waste_baskets, 2 benches, and 2 other objects; Deleted a waste_basket
I walked 7.9km in 1h45m36s
RE: https://phpc.social/@phpc_tv/116274041642323081
Now that phpc.tv and phpc.social are part of the same umbrella, I've upped my yearly contributions to their Open Collective: https://opencollective.com/phpcommunity/projects/phpc-social
Merge branch 'xdebug_3_5'
Merged pull request #1070
I walked 7.2km in 1h10m26s
Fixed issue #2405: Handle minimum path in .xdebug directory discovery
I've published a new blog post: "Human Creations", on the difference in content generation by LLMs, and the creation of text, art and code by humans.
You can find it at https://derickrethans.nl/human-creations.html or at @blog
I walked 7.8km in 1h38m32s
RE: https://phpc.social/@afilina/116274024588235234
It's good to see that more and more people are realising that the Web can be for-good, without all the enshittification.
That's why I'm happy to see endeavours like phpc.tv springing up, and helping out where I can.
Taking back the control of how the Web is for people, by people, without big tech making it all shit.
Created a waste_basket; Updated 5 crossings and a bicycle_parking
I walked 10.7km in 2h35m10s


Shortlink
This article has a short URL available: https://drck.me/shrturl-8ju