diff --git a/config/initializers/8_default_url_options.rb b/config/initializers/8_default_url_options.rb
new file mode 100644
index 0000000000000000000000000000000000000000..8c1b56846d2571fadb0e4eda8d9de64f7e6d948a
--- /dev/null
+++ b/config/initializers/8_default_url_options.rb
@@ -0,0 +1,13 @@
+unless Rails.env.test?
+  default_url_options = {
+    host:        Gitlab.config.gitlab.host,
+    protocol:    Gitlab.config.gitlab.protocol,
+    script_name: Gitlab.config.gitlab.relative_url_root
+  }
+
+  unless Gitlab.config.gitlab_on_standard_port?
+    default_url_options[:port] = Gitlab.config.gitlab.port
+  end
+
+  Rails.application.routes.default_url_options = default_url_options
+end