Using Phoenix as a "redirect server". Anyone else?

This has been a super-useful app for me and Phoenix is ridic fast and efficient with memory. Here’s the gist of it. There are a lot more entries in the actual app:

In router.ex:

    get("/oregon_revised_statutes", RedirectController, :ors_statutes)
    get("/ors/volume/:number",      RedirectController, :ors_volume)

And in redirect_controller.ex:

  def ors_statutes(conn, _), do: perm_redirect(conn, to: "#{@opl_url}/statutes")

  def ors_volume(conn, %{"number" => number}) do
    perm_redirect(conn, to: "#{@opl_url}/statutes/ors_volume_#{number}")

I’ve got all my old deprecated domain names pointed at this app, and it redirects to the new servers. Architecture-wise, it’s been a success: Usually, these legacy redirects would be in my actual app (unrelated code), or in a service like Cloudflare (good, but gets expensive.) The separate redirect server keeps these legacy business concerns (reallly SEO concerns) out of my production business app. And it will run on the cheapest Gigalixir instance.

I’m not a huge Phoenix expert. Anybody doing this a different way?

1 Like

Yes, I’d write a helper which allows to do the job in router

redirect("/oregon_revised_statutes", to: "/statuses")
redirect("/ors/volume/:number", to: "/statutes/ors_volume_:number")

and maybe use a different file which defines these routes. Another service is overkill IMO.

EDIT: ah, I see, domain name had been changed as well. Then another service is OK :slight_smile:

1 Like

Nice! Haven’t used it in a long time but I’ve used (Apache) mod_rewrite for redirects in the past - I’d be curious to know it performs compared to your Phoenix app :smiley:

1 Like

These days I’d reach for nginx or caddy but admittedly the approach chosen by OP is more programmable and likely a little bit more manageable.


Yeah I’d agree - I hated having to write rewrite rules using mod_rewrite :lol:

Could be a great selling point if the Phoenix app performs just as well :003: