469,306 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

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 29510
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Paul | last post: by
8 posts views Thread by Victor | last post: by
8 posts views Thread by Mantorok | last post: by
1 post views Thread by David | last post: by
4 posts views Thread by =?Utf-8?B?SlA=?= | last post: by
56 posts views Thread by UKuser | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.