How To Redirect Web Page From A Specfic Page In Sinatra?
In Sinatra, how to redirect a web page from a specific page? require 'sinatra' get '/A' do redirect '/B' end get '/B' do # if comes from A # 'IT COMES FROM A'
Solution 1:
The information of the HTTP referrer can be retrieved via:
request.referrer
But if it is a redirect initiated by the server, it doesn't count as the referrer to the target page. In short terms:
If /A redirects to /B because the server told the client the page moved (status 302), the referrer is not /A but the page which linked to /A or nothing, if /A got requested directly.
To answer the question: You have to use client side redirecting in order to get your idea working. Javascript can do the trick (placed on /A):
<scripttype="text/javascript">window.location = '/B';</script>
Solution 2:
You can check for the referrer path to do so
URI(request.referrer).path
Better approach would be to pass some parameter in the query string and you can redirect based upon its presence.
Post a Comment for "How To Redirect Web Page From A Specfic Page In Sinatra?"