473,405 Members | 2,421 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 Redirect to another page

In a Python script running under CGI, can I programatically redirect the
program to another page. Assume that I have a static HTML page that I want
displayed (e.g. index.htm). Other than 'print ...' is there any way to
redirect to this URL (for example, like Response.Redirect() in ASP)?

Many thanks.
Jul 18 '05 #1
12 30769
Andrew Chalk:
Assume that I have a static HTML page that I want
displayed (e.g. index.htm). Other than 'print ...' is there any way to
redirect to this URL (for example, like Response.Redirect() in ASP)?


The Response.Redirect likely works by putting something in
the header. The HTML page you have doesn't have access to
the header. However, you can use the meta tag to tell the
browser to look elsewhere. But that won't work for tools which
don't parse the HTML.

It's an easy web search (once you know the right keywords :) -
"header redirect meta" and I found
http://vancouver-webpages.com/META/FAQ.html#redirect
"How can I redirect the user to another page ?"
with three different answers

Andrew
da***@dalkescientific.com

Jul 18 '05 #2
In message <NW*********************@newssvr11.news.prodigy.co m>
"Andrew Chalk" <ac****@XXXmagnacartasoftware.com> wrote:
In a Python script running under CGI, can I programatically redirect the
program to another page.
Do you mean redirect the client browser ?
Assume that I have a static HTML page that I want displayed (e.g.
index.htm). Other than 'print ...' is there any way to redirect to this
URL (for example, like Response.Redirect() in ASP)?


Assuming you mean not to print the whole page, when you say "Other than
'print ...'" then;

print "Location: http:abcxyz.index.html"

AFAIUI it simply sends a redirect header.

--
___
|im ---- ARM Powered ----
Jul 18 '05 #3
In message <09************@worthy.demon.co.uk>
Tim Howarth <ti*@worthy.demon.co.uk> wrote:
In message <NW*********************@newssvr11.news.prodigy.co m>
"Andrew Chalk" <ac****@XXXmagnacartasoftware.com> wrote:
In a Python script running under CGI, can I programatically redirect the
program to another page.


print "Location: http:abcxyz.index.html"


Or even a properly formed URL !

--
___
|im ---- ARM Powered ----
Jul 18 '05 #4
Thanks, good web search! I couldn't get "Location:URL" to work but META did.

Regards.

"Andrew Dalke" <ad****@mindspring.com> wrote in message
news:4n****************@newsread4.news.pas.earthli nk.net...
Andrew Chalk:
Assume that I have a static HTML page that I want
displayed (e.g. index.htm). Other than 'print ...' is there any way to
redirect to this URL (for example, like Response.Redirect() in ASP)?


The Response.Redirect likely works by putting something in
the header. The HTML page you have doesn't have access to
the header. However, you can use the meta tag to tell the
browser to look elsewhere. But that won't work for tools which
don't parse the HTML.

It's an easy web search (once you know the right keywords :) -
"header redirect meta" and I found
http://vancouver-webpages.com/META/FAQ.html#redirect
"How can I redirect the user to another page ?"
with three different answers

Andrew
da***@dalkescientific.com

Jul 18 '05 #5
Tim Howarth <ti*@worthy.demon.co.uk> wrote:
print "Location: http://abcxyz/index.html" AFAIUI it simply sends a redirect header.


Yep; however, if you include a relative URI with no hashpart:

print 'Location: /index.html'
print

Then the server should send that page to the browser directly, without
sending a redirect back to the browser. This may be preferable in
some cases.

(The second print is needed to end the CGI response headers.)

Full spec here:

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

(Using JavaScript or meta-refresh to do redirects is almost always a
really terrible idea.)

--
Andrew Clover
mailto:an*@doxdesk.com
http://www.doxdesk.com/
Jul 18 '05 #6
Tim Howarth <ti*@worthy.demon.co.uk> wrote:
print "Location: http://abcxyz/index.html" AFAIUI it simply sends a redirect header.


Yep; however, if you include a relative URI with no hashpart:

print 'Location: /index.html'
print

Then the server should send that page to the browser directly, without
sending a redirect back to the browser. This may be preferable in
some cases.

(The second print is needed to end the CGI response headers.)

Full spec here:

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

(Using JavaScript or meta-refresh to do redirects is almost always a
really terrible idea.)

--
Andrew Clover
mailto:an*@doxdesk.com
http://www.doxdesk.com/
Jul 18 '05 #7
On Wed, 24 Sep 2003, Andrew Chalk wrote:
In a Python script running under CGI, can I programatically redirect the
program to another page. Assume that I have a static HTML page that I
want displayed (e.g. index.htm). Other than 'print ...' is there any way
to redirect to this URL (for example, like Response.Redirect() in ASP)?


you have two options:

- write a Location header; the web server will notice it and spit out the
file you specify

- write Status and Location headers, giving status 302 (or 303); the web
server will notice the Status header and give the client the appropriate
status code; the client will then follow the redirect you give it in the
Location header

see:

http://hoohoo.ncsa.uiuc.edu/cgi/out.html
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

tom

--
One chants out between two worlds Fire - Walk With Me.

Jul 18 '05 #8
an********@doxdesk.com (Andrew Clover) writes:
[...]>
(Using JavaScript or meta-refresh to do redirects is almost always a
really terrible idea.)


I know I don't like them "on principle", but what practical problems
do they cause? Do proper HTTP redirects avoid the "back button trap",
maybe? I've never noticed...
John
Jul 18 '05 #9
What is wrong with meta-refresh?

"Andrew Clover" <an********@doxdesk.com> wrote in message
news:2c**************************@posting.google.c om...
Tim Howarth <ti*@worthy.demon.co.uk> wrote:
print "Location: http://abcxyz/index.html"

AFAIUI it simply sends a redirect header.


Yep; however, if you include a relative URI with no hashpart:

print 'Location: /index.html'
print

Then the server should send that page to the browser directly, without
sending a redirect back to the browser. This may be preferable in
some cases.

(The second print is needed to end the CGI response headers.)

Full spec here:

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

(Using JavaScript or meta-refresh to do redirects is almost always a
really terrible idea.)

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

Jul 18 '05 #10
Andrew Chalk wrote:
What is wrong with meta-refresh?


The use of the Location header is much more direct.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ An undevout astronomer is mad.
\__/ Edward Young
Jul 18 '05 #11
[Andrew Chalk wrote]
What is wrong with meta-refresh?


It is claimed that search engines treat meta-refresh with suspicion. I
don't know if this is true or not. The following article (as an
example, this is just the first link I found when googling for "abuse
meta refresh"), claims that Altavista bans sites that use a meta
refresh period below 30 seconds.

META Refresh And Search Engines
http://www.netmechanic.com/news/vol4/promo_no15.htm

regards,

--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
Jul 18 '05 #12
John J. Lee <jj*@pobox.com> wrote:
I know I don't like them "on principle", but what practical problems
do they cause? Do proper HTTP redirects avoid the "back button trap",
maybe?
Yes, they do. They are also more widely supported by robots (including
search engine spiders) and older and non-desktop browsers (as well as
newer browsers which can have meta-refresh and/or JavaScript disabled).

An HTTP redirect is an unequivocal statement that a resource is elsewhere,
at a transport level. It can be understood and acted on by agents with no
knowledge of HTML or JavaScript (for example Python's urllib), and can
potentially be used to automatically update links.

Meta-refresh (or, less commonly used, Refresh as an HTTP header) was
designed for re-fetching pages that update themselves, such as webcams.
It's still useful for this, although it has yet to be standardised.

Using meta-refresh or JavaScript for a redirect is really a misuse,
and is needed only:

a. When you need to set a cookie at the same time as doing a redirect.
Some browsers will not allow a cookie to be set in anything but a
'200 OK' response.

b. When your web hosts are exceedingly crappy and don't allow you to
do proper redirects through server config or CGI.

In these cases I prefer to use JavaScript's location.replace() method (which
also avoids the back button trap), combined with a short-delay meta-refresh
as backup and a plain HTML link in the returned page as backup for the
backup (for robots etc).

Alan Kennedy <al****@hotmail.com> wrote:
It is claimed that search engines treat meta-refresh with suspicion.
I don't know if this is true or not.


It's not easy to tell, but Google is known to have 'anti-cloaking' measures
for detecting search engine abuse. Since meta-refresh is commonly used for
sending browsers to a different page than engines, it is possible that
a meta-refresh - likely combined with other indicators Google could find
suspicious - might result in a PR0 block.

More importantly, many robots won't follow a meta-refresh at all. (After all,
they don't want to end up following an infinitely refreshing webcam page.)
So a backup <a> link should always be included.

--
Andrew Clover
mailto:an*@doxdesk.com
http://www.doxdesk.com/
Jul 18 '05 #13

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

Similar topics

3
by: Paul | last post by:
I'm not getting the results I want when I use Response.Redirct in a ASP page. I enter this line of code in a asp page from domain1.com. Response.Redirect...
2
by: T Conti | last post by:
Howdy: I have converted a huge ASP page over to .Net (C#). The old page has been will be removed from our site, but I need to have a dummy page there that will redirect the user to the new site...
8
by: Victor | last post by:
I need to redirect to another web page, but that redirect will include the submission of form data. So, unlike ServerXMLHTTP which stays on the originating web page, I need the script to redirect...
3
by: Pooja Renukdas | last post by:
Hello, I have this web site where only two pages have to be secure pages and I need to call them using https, but since I have my development server and my production web server, I dont want to...
8
by: Mantorok | last post by:
Hi all When I start a new thread that tries to call: HttpContext.Current.Response.Redirect() It fails as Current returns null, is there anyway to access the current httpcontext from within...
1
by: David | last post by:
I need to redirect to a page and HTTP Post data. The Response.Redirect does not work and the HTTPREQUEST option calls the page and waits for a response, but I need to transfer control to the...
6
by: Coleen | last post by:
Hi all :-) I need to redirect to multiple pages on click of a transmit button, without redisplaying each page. This redirection is to capture session variables that are created on each page and...
1
by: rouellette | last post by:
Is it possible to redirect to another page in your application from the start page BEFORE the user has been authenticated if you're using FORMS authentication? I can't seem to get it to work. ...
4
by: =?Utf-8?B?SlA=?= | last post by:
All the sudden my app has started to loose Session values after a Response.Redirect to another page in the same project. Ive read several post about setting the Terminate Boolean to false to solve...
56
by: UKuser | last post by:
Hi, I'm not sure if this can be done as I've searched the web and this forum. I am using an online merchant provider and I must post certain variables to their webforms through a form on my...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.