diff --git a/gitlab_deps/deps.py b/gitlab_deps/deps.py
index 76068e47025056b4d0b0f74fe85766500bb5c40d..b27a15c2a29d7b7a1ced972a3186952b9a26405d 100644
--- a/gitlab_deps/deps.py
+++ b/gitlab_deps/deps.py
@@ -99,13 +99,13 @@ def docker_image_to_project(docker_image, registry_hostname):
         return m[3], branch
 
 
-_url_rx = re.compile(r'^(https?://[^/]+/)([^:]+)(:.*)?$')
+_url_rx = re.compile(r'^https?://[^/]+/([^:]+)(:(.*))?$')
 
 
 def url_to_project(url, gitlab_url):
     m = _url_rx.match(url)
-    if m and m[1] == gitlab_url:
-        return m[2], m[3] or DEFAULT_BRANCH
+    if url.startswith(gitlab_url) and m and m[1] == gitlab_url:
+        return m[1], m[3] or DEFAULT_BRANCH
 
 
 def not_null(l):