Browse Source

Keep query string when redirecting

Thibaut 11 years ago
parent
commit
04bf8f35eb
1 changed files with 6 additions and 2 deletions
  1. 6 2
      lib/app.rb

+ 6 - 2
lib/app.rb

@@ -105,6 +105,10 @@ class App < Sinatra::Application
     def doc_index_page?
       @doc && request.path == "/#{@doc['slug']}/"
     end
+
+    def query_string_for_redirection
+      request.query_string.empty? ? nil : "?#{request.query_string}"
+    end
   end
 
   before do
@@ -165,9 +169,9 @@ class App < Sinatra::Application
     return 404 unless @doc = settings.docs[doc]
 
     if rest.nil?
-      redirect "/#{doc}#{type}/"
+      redirect "/#{doc}#{type}/#{query_string_for_redirection}"
     elsif rest.length > 1 && rest.end_with?('/')
-      redirect "/#{doc}#{type}#{rest[0...-1]}"
+      redirect "/#{doc}#{type}#{rest[0...-1]}#{query_string_for_redirection}"
     else
       erb :other
     end