dogweather
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}")
end
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?
Most Liked
dimitarvp
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.
fuelen
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 ![]()
AstonJ
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 ![]()
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








