History

Keep query string when redirecting

Thibaut committed 11 years ago

Commit 04bf8f31 parent 9ec670c1 file · +6 −2Browse files

Unified · Split

lib/app.rb+6−2
@@ -105,6 +105,10 @@ class App < Sinatra::Application · 104 unmodified lines
105105 def doc_index_page?
106106 @doc && request.path == "/#{@doc['slug']}/"
107107 end
108+
109+ def query_string_for_redirection
110+ request.query_string.empty? ? nil : "?#{request.query_string}"
111+ end
108112 end
109113
110114 before do
@@ -165,9 +169,9 @@ class App < Sinatra::Application · 54 unmodified lines
165169 return 404 unless @doc = settings.docs[doc]
166170
167171 if rest.nil?
168− redirect "/#{doc}#{type}/"
172+ redirect "/#{doc}#{type}/#{query_string_for_redirection}"
169173 elsif rest.length > 1 && rest.end_with?('/')
170− redirect "/#{doc}#{type}#{rest[0...-1]}"
174+ redirect "/#{doc}#{type}#{rest[0...-1]}#{query_string_for_redirection}"
171175 else
172176 erb :other
173177 end