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)))
))
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:
- Placing a (gensym) where it expects a function symbol
- Using lists rather than dotted lists and calling (first redirect) where it expects a symbol
- Placing a quasiquote around the whole thing and an unquote around (first redirect)
What would be a good way to accomplish this?
Although you already solved the problem I figured I might add this as an alternative. If you don't want to make a whole custom acceptor, you can add an around-method on
HUNCHENTOOT:ACCEPTOR-DISPATCH-REQUEST
forHUNCHENTOOT:EASY-HANDLER
.Let's make an acceptor and one page first:
Then redirect
/bar
and/quux
to/foo
:Edit: Use around method instead of before. I initially figured that letting it call the main method normally would be necessary for any logging/etc. happening there, but after further testing it doesn't seem to be.
Let's guess:
DEFINE-EASY-HANDLER
is a macro.Three typical ways to solve that:
call the underlying layer instead and don't use the macro - if the underlying layer is available for the programmer
write and use a macro which
expands
(defredirects (a . a1) (b . b1) (c . c1)))
intoeval
(orcompile
andfuncall
if possible) in the loop for each form.This solution works. I definitely appreciate feedback regarding whether or not it's best practice.