301 vs 302 redirects using Phoenix
If you need a temporary redirect aka 302
using the redirect/2
function:
def redirect_show(conn, %{"id" => id}) do
conn
|> redirect(to: Routes.blog_path(conn, :show, id))
end
If you are permanently moving a page and want to indicate that to mother Google and the rest of the web you need to first execute the put_status/1
function and then pipe to redirect/2
.
def redirect_show(conn, %{"id" => id}) do
conn
|> put_status(:moved_permanently)
|> redirect(to: Routes.blog_path(conn, :show, id))
end
Check out other Phoenix posts: