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
105 def doc_index_page?105 def doc_index_page?
106 @doc && request.path == "/#{@doc['slug']}/"106 @doc && request.path == "/#{@doc['slug']}/"
107 end107 end
108
109 def query_string_for_redirection
110 request.query_string.empty? ? nil : "?#{request.query_string}"
111 end
108 end112 end
109 113
110 before do114 before do
@@ -165,9 +169,9 @@ class App < Sinatra::Application · 54 unmodified lines
165 return 404 unless @doc = settings.docs[doc]169 return 404 unless @doc = settings.docs[doc]
166 170
167 if rest.nil?171 if rest.nil?
168 redirect "/#{doc}#{type}/"172 redirect "/#{doc}#{type}/#{query_string_for_redirection}"
169 elsif rest.length > 1 && rest.end_with?('/')173 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}"
171 else175 else
172 erb :other176 erb :other
173 end177 end