Cool history.replaceState redirect short URL trick - lmmx/devnotes GitHub Wiki
For a website which has redirect links with more readable names, you can
- pull in said listing (maybe not cross-origin, but maybe - see site map parsing example)
- update the presented URL (if on that page) so that anyone wanting to share it will use the more readable redirect
- if anyone doesn't have a modern browser it won't change anyway! :-)
Very neat in practice!
function sneakyRename() {
if (window.history && window.history.replaceState && /\/post\/\d\d*/.test(window.location.href)) {
listingobj = JSON.parse('{"98651274326":"a-bioinformatics-walk-through-accessing-interfaces","93627278206":"pairing-and-stacking","99087270391":"systems-consequences-of-amplicon-formation-in-human-breast-cancer","98747455066":"gibbs-graphical-method","104293317361":"readcube-free-access","99987684211":"histone-modification-chromatin-signalling-and-structure","102462945826":"NoLS-charge-dependence","105463397986":"cochrane-ecig","104967247506":"comparison-of-geometric-motifs-common-on-greek","106792273506":"light-reg-miRNAs","106896871556":"mRNA-eukaryotic-ribosomal-interaction","105009233476":"seasons-tweetings","113037351906":"tamara-munzner-data-stories","107306256066":"miR17-92-structure","107135276326":"evolutionary-biochemistry","112368006111":"one-weird-rmd-trick","113259869341":"gdoc-rmd-gui","113902806836":"SICP-Perlis-foreword","114288240626":"Walden","105715861371":"AD-amyloid-hypothesis","91135554841":"molecular-motions-inside-the-cell","106999236456":"ars-tumorigenesis","99496457401":"chemistrynobel2014","107211261776":"post-transcriptional-circadian-genomics","107431933266":"evol-folding-opt","107499936546":"an-11-PUM-repeat-fold","112703796076":"modular-workbook","114381869481":"siderophores-and-peer-review","114406424846":"Gaussian-building","114644897706":"family-values","115063341476":"we-need-to-talk-about-crispr","115263176916":"chemiluminescence-aka-upe","115493784606":"debunking-bryan-sykes-times","115935749316":"the-hedgehog-and-the-fox","116152833156":"dat-bids","116172272726":"the-wet-idp","116210623861":"political-inheritance"}');
var current_post_id = window.location.href.match(/\/(\d\d*)/)[1];
var current_pagename = listingobj[current_post_id];
if (current_pagename !== undefined) history.replaceState(null, null, '/'+current_pagename);
}
}
On page load (including AJAX page loads) the likes of
... where the post title is appended to the ID, changes to the redirect short URL:
:tada:
Looks much nicer in the browser, and much more readable 'down the line' if someone chooses to share the page (they don't have to be aware of the redirects I've set up to take advantage of them)
- Sites like Twitter truncate URLs so only the uninformative '/post/1234…' gets seen
- Other sites like Wordpress automatically give at least date-informative URLs, and self-hosted PHP nightmares obviously have these neat customisable short URLs. This is the cheat's way to get that