diff --git a/app/assets/javascripts/api.js.coffee b/app/assets/javascripts/api.js.coffee
index ca721517867ebc08b831114ebf4fc55570e52ce5..7cac971f247f91a1e78663ece399f855fa79ece4 100644
--- a/app/assets/javascripts/api.js.coffee
+++ b/app/assets/javascripts/api.js.coffee
@@ -50,4 +50,5 @@
       callback(users)
 
   buildUrl: (url) ->
+    url = gon.relative_url_root + url if gon.relative_url_root.present?
     return url.replace(':version', gon.api_version)
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 32b1246601de7fbd3eca5fce5938fdb29a352713..22fe5abacb335344b252432d92be143e9bebdaa7 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -155,5 +155,6 @@ class ApplicationController < ActionController::Base
     gon.api_version = Gitlab::API.version
     gon.api_token = current_user.private_token if current_user
     gon.gravatar_url = request.ssl? ? Gitlab.config.gravatar.ssl_url : Gitlab.config.gravatar.plain_url
+    gon.relative_url_root = Gitlab.config.gitlab.relative_url_root
   end
 end