473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

CGI redirection: let us discuss it further

I am now programming python scripts for CGI environment. The
redirection has been discussed in this forum for over one hundred
times. I have seen most of them, but still have some questions:

1. Are there any method (in python of course) to redirect to a web page
without causing a "Back" button trap(ie, when user click the back
button on their web browser, they are redirect to their current page,
while their hope is probably to go back to the last page they have
seen, rather than the redirection page with a "Location: url" head and
blank content.)?

2. Are there any method to use relative path, rather than full absolute
URI path in "Location: url"? It is very essential for later transplant
work, e.g.,transplant a folder of cgi scripts from one web server to
another, with different URL.

Thank you.

Mar 27 '06 #1
8 2056
Sullivan WxPyQtKinter enlightened us with:
1. Are there any method (in python of course) to redirect to a web
page without causing a "Back" button trap(ie, when user click the
back button on their web browser, they are redirect to their current
page, while their hope is probably to go back to the last page they
have seen, rather than the redirection page with a "Location: url"
head and blank content.)?


I don't know if this is possible using CGI. I use CherryPy, and it has
an InternalRedirect method. Same is true for mod_python and Apache.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Mar 27 '06 #2
I V
Sullivan WxPyQtKinter wrote:
1. Are there any method (in python of course) to redirect to a web page
without causing a "Back" button trap(ie, when user click the back
button on their web browser, they are redirect to their current page,
while their hope is probably to go back to the last page they have
seen, rather than the redirection page with a "Location: url" head and
blank content.)?
I guess this may vary from browser to browser, but on Mozilla at least,
if your CGI script returns one of the 300 status codes, then the
redirect page doesn't get added to the browser history, and so the back
button works as expected.
2. Are there any method to use relative path, rather than full absolute
URI path in "Location: url"? It is very essential for later transplant
work, e.g.,transplant a folder of cgi scripts from one web server to
another, with different URL.


You don't have to use absolute URLs in a Location: header returned by a
CGI script. The web server will handle relative URLs for you. See the
CGI spec:

http://hoohoo.ncsa.uiuc.edu/cgi/out.html

Mar 27 '06 #3
Dennis Lee Bieber enlightened us with:
I suspect the desired function may be browser specific, since it
sounds like one would need to "pop" a history record to remove the
"redirect" page from the list...


That's only if you think from the browser's point of view. An internal
redirect goes unnoticed by the browser, hence there is no need for
such history manipulation. With an internal redirect there is no
"redirect page" at all, since the new URL is fetched from within the
server, and sent to the browser as the response to the requested URL.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Mar 28 '06 #4
Sullivan WxPyQtKinter wrote:
1. Are there any method (in python of course) to redirect to a web page
without causing a "Back" button trap... rather than the redirection page
with a "Location: url" head
What's wrong with the redirection page?

If there's really a necessary reason for not using an HTTP redirect
(for example, needing to set a cookie, which doesn't work cross-browser
on redirects), the best bet is a page containing a plain link and
<script>-redirect, using location.replace() to avoid the back button
trap.
2. Are there any method to use relative path, rather than full absolute
URI path in "Location: url"? It is very essential for later transplant
work, e.g.,transplant a folder of cgi scripts from one web server to
another, with different URL.


Just read the name of the server (os.environ['SERVER_NAME']) to work
out what absolute URL to redirect to, whist still being portable.

Here's some code I dug up that should also cope with non-default ports
and SSL, if that's of any use:

ssl= os.environ.get('HTTPS', 'off') not in ('', 'off', 'false', 'no')
scheme= ['http', 'https'][ssl]
port= ['80', '443'][ssl]
host= os.environ.get('SERVER_NAME', 'localhost')
url= '%s://%s:%s' % (scheme, host, os.environ.get('SERVER_PORT',
port))
if url.endswith(':'+port):
server= server[:-(len(port)+1)]
url+= path

(You *can* pass relative URLs back to the web server in a Location:
header, but this should do an internal redirect inside the server,
which may not be what you want.)

--
And Clover
mailto:an*@doxdesk.com
http://www.doxdesk.com/

Mar 28 '06 #5
Just read the name of the server (os.environ['SERVER_NAME']) to work
out what absolute URL to redirect to, whist still being portable.

Here's some code I dug up that should also cope with non-default ports
and SSL, if that's of any use:

ssl= os.environ.get('HTTPS', 'off') not in ('', 'off', 'false', 'no')
scheme= ['http', 'https'][ssl]
port= ['80', '443'][ssl]
host= os.environ.get('SERVER_NAME', 'localhost')
url= '%s://%s:%s' % (scheme, host, os.environ.get('SERVER_PORT',
port))
if url.endswith(':'+port):
server= server[:-(len(port)+1)]
url+= path

(You *can* pass relative URLs back to the web server in a Location:
header, but this should do an internal redirect inside the server,
which may not be what you want.)

Sorry I do not quite understand what is the difference between an
internal redirection and an external one?
--
And Clover
mailto:an*@doxdesk.com
http://www.doxdesk.com/


Mar 28 '06 #6
an********@doxdesk.com enlightened us with:
What's wrong with the redirection page?

If there's really a necessary reason for not using an HTTP redirect
(for example, needing to set a cookie, which doesn't work
cross-browser on redirects), the best bet is a page containing a
plain link and <script>-redirect, using location.replace() to avoid
the back button trap.


That's a very ugly hack. For starters, it requires much more traffic
than an internal redirect. Second, the URL changes, which might not be
wanted. Third, it requires JavaScript for something that can be done
without it.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Mar 28 '06 #7
Sullivan WxPyQtKinter enlightened us with:
Sorry I do not quite understand what is the difference between an
internal redirection and an external one?


External:
- Browser requests URL A
- Server responds "Go to URL B"
- Browser requests URL B
- Server responds with contents of B
- Browser displays B

Internal:
- Browser requests URL A
- Server responds with contents of B
- Browser displays B

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Mar 28 '06 #8
Well, in that case, the internal direction is just what I need. Thank
you so much for help.

Mar 29 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
52
by: Gerard M Foley | last post by:
Can one write a webpage which is not displayed but which simply redirects the user to another page without any action by the user? Sorry if this is simple, but I am sometimes simple myself. ...
8
by: Luciano A. Ferrer | last post by:
Hi! I was following the http://www.seomoz.org/articles/301-redirects.php article, trying to do that with one of my test sites I added this to the .htaccess file: RewriteEngine On RewriteCond...
13
by: souissipro | last post by:
Hi, I have written a C program that does some of the functionalities mentionned in my previous topic posted some days ago. This shell should: 1- execute input commands from standard input,...
1
by: comp.lang.php | last post by:
require_once("/users/ppowell/web/php_global_vars.php"); if ($_GET) { // INITIALIZE VARS $fileID = @fopen("$userPath/xml/redirect.xml", 'r'); $stuff = @fread($fileID,...
13
by: Massimo Fabbri | last post by:
Maybe it's a little OT, but I'll give it try anyway.... I was asked to maintain and further develop an already existing small company's web site. I know the golden rule of "eternal" URIs, but...
4
by: Phil | last post by:
I have a php script that queries some Oracle DB and outputs a single line of plain text with <brat the end for each query. This is Apache2, php4.4.8 and Oracle Instant Client 10.1.0.5 all on CentOS...
9
by: Nick | last post by:
Hi there, I'm passing an HTML encoded string to an URL in the query parameter. This query string works perfect in the website if you are already logged on, if you are not logged on the...
4
by: Neil Gould | last post by:
Anthony Jones wrote: That it is awaiting user action. Since a While/Wend or some other on-going background activity of a script appears to provide exceptions to the above statement, your usage...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.