Avatar

kiss redirect

posted: Mon, Jun 26, 2023 | tagged: | | dev | web
return to blog home |


keeping it simple stud, redirect style

Redirect code

I was looking up to see if there was an integrated way to handle page redirects with 11ty expecting there to be some crazy Javascript code that I'd need to implement. I found some articles that talked about making this work when hosting 11ty sites on Netlify. I'm presently using a traditional web hosting provider, so that use case doesn't quite cut it for me.

So after searching and reading for a while, I thought of a different technique that wasn't nearly as potentially complicated and rather simple and elegant. I built in some logic with my base Nunjuck template where I check for the a variable of redirecturl in the template frontmatter, and if that value is true I include a simple meta redirect in the HTML template set to the value of the frontmatter variable pointing to the correct URL.

{% if redirecturl %}
<meta http-equiv="Refresh" content="0; url='{{ redirecturl }}'" />
{% endif %}

I really didn't expect something so simple would be so effective. But that is an itch of a desire to overengineering. Sometimes simple wins. KISS baby, KISS.


related posts

return to blog home

signature