delphi-tips icon indicating copy to clipboard operation
delphi-tips copied to clipboard

Redirect URLS in form `/<n>` to `/tips/<n>`

Open delphidabbler opened this issue 3 years ago • 4 comments

Using the URL tips.delphidabbler.com/<n> instead of tips.delphidabbler.com/tips/<n> is much friendlier. Is there any way to do this using the jekyll-redirect-from plugin?

delphidabbler avatar May 23 '22 08:05 delphidabbler

It can be done with jekyll-redirect-from.

However the plugin will create 200+ numbered .html files in the root directory. This could cause a problem if there's ever a 404.html custom error page and the number of tips becomes >= 404!

delphidabbler avatar Sep 13 '22 00:09 delphidabbler

It may be better to rename tips as tip: it feels more intuitive to me to request tips.delphidabbler.com/tip/42 than tips.delphidabbler.com/tips/42.

Another possibility is to rename tips as id.

If tips does get renamed we would need to add a

redirect_from:
  - /tips/xxx

statement to every tip's front matter, where xxx is the tip number.

delphidabbler avatar Sep 13 '22 00:09 delphidabbler

Another possibility may be to use a query string for the tip id, e.g. tips.delphidabbler.com/?t=42.

Maybe an anchor could be used instead: tips.delphidabbler.com/#42

But then the main index.html would have to check for the query string or anchor using Javascript and either redirect to the tip page if there's a query string or display the home page if not.

Neither approach looks pretty!

delphidabbler avatar Sep 13 '22 00:09 delphidabbler

Yet another possibility is to

  1. Rename tips directory to tip as suggested above

  2. Add the required

    redirect_from:
      - /tips/xxx
    

    front matter to redirect from tips.

  3. Add a further entry to the redirect_from front matter:

    redirect_from:
      - /tips/xxx
      - /t/xxx
    

    to add support for urls of the form tips.delphidabbler.com/t/xxx.

This way all the following forms of URL would be valid:

  1. tips.delphidabbler.com/tip/xxx (the canonical form)
  2. tips.delphidabbler.com/t/xxx (the shorthand form)
  3. tips.delphidabbler.com/tips/xxx (the old style form)

Charging the canonical form from tips.delphidabbler.com/tips/xxx to tips.delphidabbler.com/tip/xxx might give Google's canonical form algorithm a headache for a while though!

delphidabbler avatar Oct 14 '22 02:10 delphidabbler