473,657 Members | 2,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2074
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 InternalRedirec t 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.replac e() 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*@doxd esk.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*@doxd esk.com
http://www.doxdesk.com/


Mar 28 '06 #6
an********@doxd esk.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.replac e() 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
5801
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 to execute the code until the browser send his reply to the header instruction. So an exit(); after each redirection won't hurt at all
52
5428
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. Happy New Year -- Gerry
8
2525
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 %{HTTP_HOST} !^domain\.com.ar RewriteRule ^/(.*) http://domain.com.ar/$1
13
2693
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, and also from a file conatining the commands 2- does the redirection of the input and output from and to files. 3- retrieve the environment variables like HOME,..
1
3520
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, @filesize("$userPath/xml/redirect.xml")); @fclose($fileID); // XML PARSE
13
4330
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 in this case changing them cannot be avoided as they were badly chosen when thwe site was first delevoped: URLs with spaces, typos, etc. So I have to use new URLs and put the content in them.
4
3949
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 4.4 32bit. Php does run as an Apache SO. It works perfectly if I just hit the page in a web-browser (output to browser). It works *perfectly* from the command line (dumps the text to the file per the redirect)
9
2005
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 application calls FormsAuthentication.RedirectToLoginPage() then the URL becomes malformed. I then recieve the following error, "The return URL specified for request redirection is invalid."
4
1301
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 seems to be a distinction without a difference. Could you clarify? Yes. Could be. From my perspective, "members.asp" is in a sense a form (though
0
8399
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8312
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8827
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4159
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.