OSDN Git Service

Remove .git from project url end redirect
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Mon, 14 Oct 2013 10:27:39 +0000 (13:27 +0300)
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Mon, 14 Oct 2013 10:27:39 +0000 (13:27 +0300)
Ex. redirect from
  localhost/group/project.git
to
  localhost/group/project

It used to prevent 404 error when follow submodule http link
like http://localhost/group/project.git

app/controllers/application_controller.rb

index d974600..85b9586 100644 (file)
@@ -63,6 +63,15 @@ class ApplicationController < ActionController::Base
   def project
     id = params[:project_id] || params[:id]
 
+    # Redirect from
+    #   localhost/group/project.git
+    # to
+    #   localhost/group/project
+    #
+    if id =~ /\.git\Z/
+      redirect_to request.original_url.gsub(/\.git\Z/, '') and return
+    end
+
     @project = Project.find_with_namespace(id)
 
     if @project and can?(current_user, :read_project, @project)