输出传入参数的CGI脚本

2024-04-29 19:28:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试编写一个python cgi脚本,它将我重定向到一个打印出一个传入参数的页面。你知道吗

重写规则如下所示:RewriteRule^(.*)$ /cgi-bin/redirect.py?url=%{HTTP_HOST}$1 [L,QSA,PT].

基本上我只想打印出<h1></h1>标记之间的参数url。我从来没有写过cgi脚本之前,所以任何建议将不胜感激。你知道吗


Tags: py脚本httphosturl参数bin规则
2条回答

对于Hello World类型的程序有lots of resources on the internet。或者你可以用standard documentation来得到答案。你知道吗

我不知道“[L,QSA,PT]”是做什么的,但我会做一些类似^(.*)$ /cgi-bin/redirect.py

你知道吗重定向.py应该看起来像:

#!/usr/bin/env python
print """Content-type: text/html

<html><head><title>Redirect</title></head><body>
<h1>%s/%s</h1></body></html>"""%(os.environ['HTTP_HOST'], os.environ['REQUEST_URI'])

我没有测试过,所以我可能完全错了:-)

相关问题 更多 >