diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb
index 220e3d2271f751d6d6462d62fe2d562e73d383d1..0b7a0d47caf7b27b1f15978f5735c1c2fe807b0b 100644
--- a/lib/extracts_path.rb
+++ b/lib/extracts_path.rb
@@ -51,7 +51,7 @@ module ExtractsPath
     return pair unless @project
 
     # Remove project, actions and all other staff from path
-    input.gsub!("/#{@project.path_with_namespace}", "")
+    input.gsub!(/^\/#{Regexp.escape(@project.path_with_namespace)}/, "")
     input.gsub!(/^\/(tree|commits|blame|blob)\//, "") # remove actions
     input.gsub!(/\?.*$/, "") # remove stamps suffix
     input.gsub!(/.atom$/, "") # remove rss feed
@@ -108,7 +108,9 @@ module ExtractsPath
       request.format = :atom
     end
 
-    @ref, @path = extract_ref(request.fullpath)
+    path = request.fullpath.dup
+
+    @ref, @path = extract_ref(path)
 
     @id = File.join(@ref, @path)