diff --git a/app/assets/javascripts/wall.js.coffee b/app/assets/javascripts/wall.js.coffee
index 4f71e6e0c35f26d154608c1a9f936936f7cbf4f7..4cc11331acaebf58a1bef6d41f075b971fa5a452 100644
--- a/app/assets/javascripts/wall.js.coffee
+++ b/app/assets/javascripts/wall.js.coffee
@@ -64,7 +64,7 @@ class Wall
     template = template.replace('{{text}}', simpleFormat(note.body))
 
     if note.attachment
-      file = '<i class="icon-paper-clip"/><a href="/files/note/' + note.id + '/' + note.attachment + '">' + note.attachment + '</a>'
+      file = '<i class="icon-paper-clip"/><a href="' + gon.relative_url_root + '/files/note/' + note.id + '/' + note.attachment + '">' + note.attachment + '</a>'
     else
       file = ''
     template = template.replace('{{file}}', file)
diff --git a/app/uploaders/attachment_uploader.rb b/app/uploaders/attachment_uploader.rb
index c0afe9686f19618c74ab23a3e0f58c38c0ed7af6..98794c9470b3d9a1f3b6288785d646fd6ceef571 100644
--- a/app/uploaders/attachment_uploader.rb
+++ b/app/uploaders/attachment_uploader.rb
@@ -21,7 +21,7 @@ class AttachmentUploader < CarrierWave::Uploader::Base
   end
 
   def secure_url
-    "/files/#{model.class.to_s.underscore}/#{model.id}/#{file.filename}"
+    Gitlab.config.gitlab.relative_url_root + "/files/#{model.class.to_s.underscore}/#{model.id}/#{file.filename}"
   end
 
   def file_storage?
diff --git a/config/application.rb b/config/application.rb
index d86fe561fa931428c10ae7394b7d1c45a0eff1d8..f3edca8c353fff795ee74ca922ec1a80e7c26da0 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -67,5 +67,9 @@ module Gitlab
 
     # Version of your assets, change this if you want to expire all your assets
     config.assets.version = '1.0'
+    
+    # Uncomment this if you are using a subdirectory
+    # Note that ENV['RAILS_RELATIVE_URL_ROOT'] in config/puma.rb may need to be changed
+    # config.relative_url_root = "/gitlab"
   end
 end
diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example
index b6a8e68bf8e4429ef5727d933d77d98fe9bd3d67..c73307cabf43b746b3acec8bbe92f25e9ac19de2 100644
--- a/config/gitlab.yml.example
+++ b/config/gitlab.yml.example
@@ -21,6 +21,7 @@ production: &base
     # WARNING: This feature is no longer supported
     # Uncomment and customize to run in non-root path
     # Note that ENV['RAILS_RELATIVE_URL_ROOT'] in config/puma.rb may need to be changed
+    # You need to uncomment config.relative_url_root in config/application.rb
     # relative_url_root: /gitlab
 
     # Uncomment and customize if you can't use the default user to run GitLab (default: 'git')
diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb
index e777ae2b78dd2f1cb38e4f4d9e941012c511fcb2..52a099c3e169705eeabbabd2f719e88207b2ce21 100644
--- a/config/initializers/session_store.rb
+++ b/config/initializers/session_store.rb
@@ -2,7 +2,8 @@
 
 Gitlab::Application.config.session_store :cookie_store, key: '_gitlab_session',
                                                       secure: Gitlab::Application.config.force_ssl,
-                                                      httponly: true
+                                                      httponly: true,
+                                                      path: (Rails.application.config.relative_url_root.nil?) ? '/' : Rails.application.config.relative_url_root
 
 # Use the database for sessions instead of the cookie-based default,
 # which shouldn't be used to store highly confidential information
diff --git a/lib/gitlab/backend/grack_auth.rb b/lib/gitlab/backend/grack_auth.rb
index a4f98ecd35011311ba394d72f4fcda79f1da632d..ddf370fbab86b6099f6ed42e3a2b7f3f5a40291c 100644
--- a/lib/gitlab/backend/grack_auth.rb
+++ b/lib/gitlab/backend/grack_auth.rb
@@ -15,7 +15,15 @@ module Grack
       @auth = Request.new(env)
 
       # Need this patch due to the rails mount
-      @env['PATH_INFO'] = @request.path
+      
+      # Need this if under RELATIVE_URL_ROOT
+      unless Gitlab.config.gitlab.relative_url_root.empty?
+        # If website is mounted using relative_url_root need to remove it first
+        @env['PATH_INFO'] = @request.path.sub(Gitlab.config.gitlab.relative_url_root,'')
+      else
+        @env['PATH_INFO'] = @request.path
+      end
+      
       @env['SCRIPT_NAME'] = ""
 
       auth!