Kemal routing redirecting a subtree
Mon, 12 Dec 2022 22:08:19 +0100This code snippet shows you how to redirect an entire subtree and remove the first part of the subtree.
This might come in useful, for example when you have outside links referencing different languages (e.g. /de /fr /it) and content paths in them, and you want to serve everything from the same endpoints.
# adding redirects for language paths get "/de/*" do |env| path_parts = env.request.path.split("/", 3) new_path = "/" if path_parts.size > 2 new_path = new_path + path_parts[2] end env.redirect new_path endCrystal Lang
Bonus tip:
puts env.inspect
puts env.request.inspect
Der Beitrag Kemal routing redirecting a subtree erschien zuerst auf pi3g.com.
Other current blog posts of the organization
Jobs of pi3g e.K.
pi3g e.K.
Als approved Raspberry Pi Reseller in Deutschland arbeiten wir seit Anfang an (2012) besonders eng mit Raspberry Pi zusammen. Wir bieten ehrliche, tiefe technische Kompetenz rund um den Raspberry Pi. Wir vertreiben Raspberry Pi sowie Coral AI hardware, und entwickeln Hardware und Software für unsere Kunden.
Unsere Plattform picockpit.com ermöglicht Nutzern ihre Pis von überall aus ganz leicht per Webinterface zu nutzen. Unsere Apps lösen echte Probleme und machen Nutzer glücklich.