diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb
index 25a1c2ca7e1add2b9c668064b828234606af592c..bf9d72ae90cb259552527b6ffec933b7a2cad9c8 100644
--- a/app/controllers/projects/artifacts_controller.rb
+++ b/app/controllers/projects/artifacts_controller.rb
@@ -36,9 +36,9 @@ class Projects::ArtifactsController < Projects::ApplicationController
   end
 
   def search
-    url = namespace_project_build_url(project.namespace, project, build)
-
     if params[:path]
+      url = namespace_project_build_url(project.namespace, project, build)
+
       redirect_to "#{url}/artifacts/#{params[:path]}"
     else
       render_404