470,636 Members | 1,543 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

CGI newb... redirect page

Hi there. I am relativly new to Python CGI and need a question answered.

I have made custom 404 error pages and have them in various web directories.

I have not been able to figure out a way to have apache use a file not
within it's own
home directory, so I was going to have a .py file in cgi-bin forward the
user on to the
correct error page.

So I have say,
/usr/www/client1/not-found.shtml
and...
/usr/www/client2/not-found.shtml

I found that cgi.print_environ() gave me the SERVER_NAME, which is what I
want.
But, this is part of a long html formatted string that cgi.print_environ()
returns.

Is there something builtin to deal with these name, value pairs as a
dictionary?
I looked throught the docs, but did not see this functionality.

Also, when I do extract this info... how do I actually do a redirect to a
certain page

Example.
User goes to www.client1.com/page_not_on_server.html
The apache conf file sends the redirect to /cgi-bin/redirect.py
Redirect.py extracts the requesting server, client1.com, then
redirects them to www.client1.com/not-found.shtml.

Thanks for your help.
Jul 18 '05 #1
3 6024
"Sean Berry" <se********@cox.net> wrote in message
news:Ayqtc.49$VI2.1@fed1read02...
Hi there. I am relativly new to Python CGI and need a question answered.

I have made custom 404 error pages and have them in various web directories.
I have not been able to figure out a way to have apache use a file not
within it's own
home directory, so I was going to have a .py file in cgi-bin forward the
user on to the
correct error page.

So I have say,
/usr/www/client1/not-found.shtml
and...
/usr/www/client2/not-found.shtml

I found that cgi.print_environ() gave me the SERVER_NAME, which is what I
want.
But, this is part of a long html formatted string that cgi.print_environ()
returns.
Okay. I found that usung os.environ yielded the results I was looking for.

Is there something builtin to deal with these name, value pairs as a
dictionary?
I looked throught the docs, but did not see this functionality.

Also, when I do extract this info... how do I actually do a redirect to a
certain page

But, I still don't know how to forward, or redirect a page.

Please help.
Example.
User goes to www.client1.com/page_not_on_server.html
The apache conf file sends the redirect to /cgi-bin/redirect.py
Redirect.py extracts the requesting server, client1.com, then
redirects them to www.client1.com/not-found.shtml.

Thanks for your help.

Jul 18 '05 #2
To do a redirect, you can simply do something such as:

print 'Location: http://new.absloute/url\r\n\r\n'
print '''
This is some html that people will never see, but generally it should
include a link to the target url'''
sys.exit()

Note that to be RFC compliant, you must give an absloute URL, although
relative ones work usually.

Furthermore, there is no reason you should have to write a script to do
redirects for error pages. See the documentation on apache.org:

http://httpd.apache.org/docs-2.0/mod...#errordocument

You can have apache use any local file, or even redirect to another
server.

On Thu, May 27, 2004 at 11:36:17AM -0700, Sean Berry wrote:
Hi there. I am relativly new to Python CGI and need a question answered.

I have made custom 404 error pages and have them in various web directories.

I have not been able to figure out a way to have apache use a file not
within it's own
home directory, so I was going to have a .py file in cgi-bin forward the
user on to the
correct error page.

So I have say,
/usr/www/client1/not-found.shtml
and...
/usr/www/client2/not-found.shtml

I found that cgi.print_environ() gave me the SERVER_NAME, which is what I
want.
But, this is part of a long html formatted string that cgi.print_environ()
returns.

Is there something builtin to deal with these name, value pairs as a
dictionary?
I looked throught the docs, but did not see this functionality.

Also, when I do extract this info... how do I actually do a redirect to a
certain page

Example.
User goes to www.client1.com/page_not_on_server.html
The apache conf file sends the redirect to /cgi-bin/redirect.py
Redirect.py extracts the requesting server, client1.com, then
redirects them to www.client1.com/not-found.shtml.

Thanks for your help.


Jul 18 '05 #3
"Phil Frost" <in****@bitglue.com> wrote in message
news:ma*************************************@pytho n.org...
To do a redirect, you can simply do something such as:

print 'Location: http://new.absloute/url\r\n\r\n'
print '''
This is some html that people will never see, but generally it should
include a link to the target url'''
sys.exit()

Note that to be RFC compliant, you must give an absloute URL, although
relative ones work usually.

Furthermore, there is no reason you should have to write a script to do
redirects for error pages. See the documentation on apache.org:

http://httpd.apache.org/docs-2.0/mod...#errordocument

You can have apache use any local file, or even redirect to another
server.

On Thu, May 27, 2004 at 11:36:17AM -0700, Sean Berry wrote:
Hi there. I am relativly new to Python CGI and need a question answered.
I have made custom 404 error pages and have them in various web directories.
I have not been able to figure out a way to have apache use a file not
within it's own
home directory, so I was going to have a .py file in cgi-bin forward the
user on to the
correct error page.

So I have say,
/usr/www/client1/not-found.shtml
and...
/usr/www/client2/not-found.shtml

I found that cgi.print_environ() gave me the SERVER_NAME, which is what I want.
But, this is part of a long html formatted string that cgi.print_environ() returns.

Is there something builtin to deal with these name, value pairs as a
dictionary?
I looked throught the docs, but did not see this functionality.

Also, when I do extract this info... how do I actually do a redirect to a certain page

Example.
User goes to www.client1.com/page_not_on_server.html
The apache conf file sends the redirect to /cgi-bin/redirect.py
Redirect.py extracts the requesting server, client1.com, then
redirects them to www.client1.com/not-found.shtml.

Thanks for your help.

Thanks very much for your response.

The reason that I am using a script is because I tried the line:

ErrorDocument 404 not-found.shtml ... and ...
ErrorDocument 404 /not-found.shtml

There is a not-found.shtml file in each domains home web directory.

This, however, did not work. It reverted to the generic version of
a 404 error page.

I figured that it was trying to look in the apache root directory for the
file, not the root of the domains web directory.

So, using this script, it will forward the user to the correct
not-found.shtml
page.

I tried looking through the apache docs, but did not see anything limiting
what type of alternate could be used.

Anything you can think of that I may be overlooking?

Thanks for your response.
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Bob Garbados | last post: by
7 posts views Thread by Donna Hawkins | last post: by
13 posts views Thread by Tim | last post: by
2 posts views Thread by Eric | last post: by
8 posts views Thread by Darrel | last post: by
1 post views Thread by gnawz | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.