Hunchentoot重定向列表 [英] Hunchentoot List of Redirects

查看:79
本文介绍了Hunchentoot重定向列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站的URI结构最近发生了巨大变化,我需要将所有旧页面重定向到它们对应的新页面.我有一个由所有旧的和新的URI成对组成的虚线列表.目前,我正在尝试为每个循环定义简单的处理程序:

The URI structure of my website changed drastically recently and I need to redirect all of the old pages to their corresponding new pages. I have a dotted list of pairs of all of the old and new URIs. At the moment I am trying to define easy handlers for each in a loop:

(let ((redirects '(("/old/uri/example-1" . "/new/uri/example-1"))))
  (dolist (redirect redirects)
    (hunchentoot:define-easy-handler (???? :uri (first redirect)) ()
       (redirect (rest redirect)))
    ))

也许有更好的方法.假设define-easy-handler是正确的,则每个easy处理器都需要一个功能符号.我尝试了以下步骤,但无济于事:

Maybe there is a better way. Assuming define-easy-handler is correct, it requires a function symbol for each easy handler. I tried the following to no avail:

  1. 将(gensym)放在需要功能符号的地方
  2. 使用列表而不是虚线列表,并在需要符号的地方调用(首次重定向)
  3. 在整个事件前放置一个准引用,在(第一次重定向)之前放置一个取消引用

什么是完成此任务的好方法?

What would be a good way to accomplish this?

推荐答案

让我们猜测:DEFINE-EASY-HANDLER是宏.

三种典型的解决方法:

  • 而是调用底层,并且不要使用宏-如果底层可供程序员使用

  • call the underlying layer instead and don't use the macro - if the underlying layer is available for the programmer

编写并使用一个宏

(defredirects (a . a1) (b . b1) (c . c1)))扩展为

(progn
  (hunchentoot:define-easy-handler (f-a ... a) () (... a1))
  (hunchentoot:define-easy-handler (f-b ... b) () (... b1))
  (hunchentoot:define-easy-handler (f-c ... c) () (... c1)))

  • 生成要调用的表单,并在每个表单的循环中使用eval(或compilefuncall)(如果可能).
    • Generate the form you want to call and use eval (or compile and funcall if possible) in the loop for each form.
    • 这篇关于Hunchentoot重定向列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆