Skip to content

Instantly share code, notes, and snippets.

@damonvjanis
Last active March 18, 2023 18:11
Show Gist options
  • Save damonvjanis/a7d98c8e5187b23146371fbbb55cfc41 to your computer and use it in GitHub Desktop.
Save damonvjanis/a7d98c8e5187b23146371fbbb55cfc41 to your computer and use it in GitHub Desktop.
defmodule MyAppWeb.Endpoint do
# All the stuff we just added
@session_options ...
socket ...
def www_redirect(conn, _options) do
if String.starts_with?(conn.host, "www.#{host()}") do
conn
|> Phoenix.Controller.redirect(external: "https://#{host()}")
|> halt()
else
conn
end
end
# Redirect all www requests to the root url
plug :www_redirect
plug ...
plug ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment