Keep query string when redirecting

pull/165/head
Thibaut 10 years ago
parent 9ec670c7d8
commit 04bf8f35eb

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

Loading…
Cancel
Save