delphidabbler / delphi-tips

A bunch of Delphi language tips migrated from the DelphiDabbler.com website, plus others.
https://tips.delphidabbler.com
31 stars 11 forks source link

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

Open delphidabbler opened 2 years ago

delphidabbler commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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!