diff --git a/changelogs/unreleased/3686_make_tarball_download_url.yml b/changelogs/unreleased/3686_make_tarball_download_url.yml
new file mode 100644
index 0000000000000000000000000000000000000000..4e75e52e3ac53c48939e910491d72afb1650f8ee
--- /dev/null
+++ b/changelogs/unreleased/3686_make_tarball_download_url.yml
@@ -0,0 +1,4 @@
+---
+title: repository archive download url now ends with selected file extension
+merge_request: 13178
+author: haseebeqx
diff --git a/config/routes/repository.rb b/config/routes/repository.rb
index edcf3ddf57b103bdf03535e5820e2762a4d177f8..2ba16035ece010a1bc674d10bd6fde9b07b53579 100644
--- a/config/routes/repository.rb
+++ b/config/routes/repository.rb
@@ -2,7 +2,7 @@
 
 resource :repository, only: [:create] do
   member do
-    get 'archive', constraints: { format: Gitlab::PathRegex.archive_formats_regex }
+    get ':ref/archive', constraints: { format: Gitlab::PathRegex.archive_formats_regex, ref: /.+/ }, action: 'archive', as: 'archive'
   end
 end
 
diff --git a/spec/controllers/projects/repositories_controller_spec.rb b/spec/controllers/projects/repositories_controller_spec.rb
index 9c55d159fa03357b5a66ac6f306aa42ebc4be952..f712d1e0d63a65cb4a52e1446e617501ef99d359 100644
--- a/spec/controllers/projects/repositories_controller_spec.rb
+++ b/spec/controllers/projects/repositories_controller_spec.rb
@@ -6,7 +6,7 @@ describe Projects::RepositoriesController do
   describe "GET archive" do
     context 'as a guest' do
       it 'responds with redirect in correct format' do
-        get :archive, namespace_id: project.namespace, project_id: project, format: "zip"
+        get :archive, namespace_id: project.namespace, project_id: project, format: "zip", ref: 'master'
 
         expect(response.header["Content-Type"]).to start_with('text/html')
         expect(response).to be_redirect
diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb
index c02409b2e0b54082d4a38e2055babadcccaf8ec8..39d44245c3fc1aced1b883fe1f5cf9b28c054bd1 100644
--- a/spec/routing/project_routing_spec.rb
+++ b/spec/routing/project_routing_spec.rb
@@ -165,15 +165,19 @@ describe 'project routing' do
   #     edit_project_repository GET    /:project_id/repository/edit(.:format)     projects/repositories#edit
   describe Projects::RepositoriesController, 'routing' do
     it 'to #archive' do
-      expect(get('/gitlab/gitlabhq/repository/archive')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq')
+      expect(get('/gitlab/gitlabhq/repository/master/archive')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', ref: 'master')
     end
 
     it 'to #archive format:zip' do
-      expect(get('/gitlab/gitlabhq/repository/archive.zip')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', format: 'zip')
+      expect(get('/gitlab/gitlabhq/repository/master/archive.zip')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', format: 'zip', ref: 'master')
     end
 
     it 'to #archive format:tar.bz2' do
-      expect(get('/gitlab/gitlabhq/repository/archive.tar.bz2')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', format: 'tar.bz2')
+      expect(get('/gitlab/gitlabhq/repository/master/archive.tar.bz2')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', format: 'tar.bz2', ref: 'master')
+    end
+
+    it 'to #archive with "/" in route' do
+      expect(get('/gitlab/gitlabhq/repository/improve/awesome/archive')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', ref: 'improve/awesome')
     end
   end