diff --git a/lib/plausible_web/templates/error/404_error.html.heex b/lib/plausible_web/templates/error/404_error.html.heex
index 89a8651976b2..e39a2072ea05 100644
--- a/lib/plausible_web/templates/error/404_error.html.heex
+++ b/lib/plausible_web/templates/error/404_error.html.heex
@@ -8,7 +8,7 @@
<% end %>
<%= if !@conn.assigns[:current_user] do %>
- <.button_link href={Routes.auth_path(@conn, :login_form, return_to: @conn.request_path)} class="mr-4">Log in
+ <.button_link href={Routes.auth_path(@conn, :login_form, return_to: @conn.request_path <> "?" <> @conn.query_string)} class="mr-4">Log in
<% end %>
<.button_link theme="bright" href={PlausibleWeb.LayoutView.home_dest(@conn)}>
Go to homepage