如何从我的网址中隐藏“ cgi-bin”,“。py”等? [英] How to hide "cgi-bin", ".py", etc from my URLs?

查看:68
本文介绍了如何从我的网址中隐藏“ cgi-bin”,“。py”等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用python的网页设计新手。启动Apache并运行,测试在cgi-bin目录中运行的python脚本。当我明确输入URL时,可获得有效的结果: ... / cgi-bin / showenv.py

Brand new to web design, using python. Got Apache up and running, test python script working in cgi-bin directory. Get valid results when I type in the URL explicitly: ".../cgi-bin/showenv.py"

但是我不希望URL看起来像那样办法。例如,在此处的stackoverflow中,显示在我的地址栏中的URL永远不会有凌乱的细节,这些细节显示了用于运行它们的脚本。它们没有cgi-bin,.py等扩展名。我该怎么做?

But I don't want the URL to look that way. Here at stackoverflow, for example, the URLs that display in my address bar never have the messy details showing the script that was used to run them. They're clean of cgi-bin, .py, etc. extensions. How do I do that?

编辑:感谢您的答复,每一个有用的东西,很多东西要学习。我现在要进行URL重写;文档中的示例看起来与我实际想要做的非常接近。但是我致力于使用python,因此必须深入研究WSGI。

Thanks for responses, every single one helpful, lots to learn. I'm going with URL Rewriting for now; example in the docs looks extremely close to what I actually want to do. But I'm committed to python, so will have to look at WSGI down the road.

推荐答案

Python编写网络的方式应用程序不是cgi-bin。通过使用 WSGI

The python way of writing web applications is not cgi-bin. It is by using WSGI.

WSGI是之间的标准接口Web服务器和Python Web应用程序或框架。 PEP 0333 对其进行了定义。

WSGI is a standard interface between web servers and Python web applications or frameworks. The PEP 0333 defines it.

使用它代替CGI没有缺点。而且您会收获很多。漂亮的URL只是您可以轻松完成的整洁的事情之一。

There are no disadvantages in using it instead of CGI. And you'll gain a lot. Beautiful URLs is just one of the neat things you can do easily.

此外,编写WSGI应用程序意味着您可以部署在任何支持WSGI界面的Web服务器上。 Apache通过使用 mod_wsgi 来做到这一点。

Also, writing a WSGI application means you can deploy on any web server that supports the WSGI interface. Apache does so by using mod_wsgi.

您可以在apache中进行如下配置:

You can configure it in apache like that:

WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.py

然后在 http://myserver.domain/myapp上的所有请求将转到myapp.py的应用程序可调用,包括 http://myserver.domain/myapp/something/here

Then all requests on http://myserver.domain/myapp will go to myapp.py's application callable, including http://myserver.domain/myapp/something/here.

示例 myapp.py

def application(environ, start_response):
    start_response('200 OK', [('Content-type', 'text/plain')])
    return ['Hello World!']

这篇关于如何从我的网址中隐藏“ cgi-bin”,“。py”等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆