如何从我的网址中删除“cgi-bin”?

时间:2021-08-01 07:08:55

I'm creating a small application on an embedded device that has a boa web server running on it. I'm creating a web application in a mixture of plain HTML pages and Perl scripts to interface with the main application. Is there a way to hide the fact that some of the pages are being served out of the cgi-bin on the device?

我正在嵌入式设备上创建一个小应用程序,它上面运行着一个boa Web服务器。我正在创建一个混合使用纯HTML页面和Perl脚本的Web应用程序来与主应用程序进行交互。有没有办法隐藏一些页面是从设备上的cgi-bin提供的?

What I have now are the following URLs.

我现在拥有以下网址。

What I would greatly prefer would be:

我更喜欢的是:

with the above URLs taking me to the appropriate index.html or index.pl document. Is there some combination of file structure and server settings that will enable this behavior?

使用上面的URL将我带到相应的index.html或index.pl文档。文件结构和服务器设置的某种组合是否会启用此行为?

I've searched Google for this, but as you can imagine I'm getting pages and pages of search results with "cgi-bin" in the URL. I'm hoping someone here has done this before.

我已经在谷歌上搜索了这个,但是你可以想象我在网址中用“cgi-bin”获取搜索结果的页面和页面。我希望以前有人这样做过。

EDIT: I should mention that I know how to do this for plain HTML pages by making separate folders in my web root, all with index.html pages. My problem is in getting this type of solution to work with .pl or .cgi files in the cgi-bin directory.

编辑:我应该提一下,我知道如何通过在我的Web根目录中创建单独的文件夹来为纯HTML页面执行此操作,所有文件夹都使用index.html页面。我的问题是让这种类型的解决方案与cgi-bin目录中的.pl或.cgi文件一起使用。

2 个解决方案

#1


Boa unfortunately doesn't appear to have any type of mod_rewrite options available to it, so you're limited in what you can do to rewrite a URL. From the boa docs here are the options you do have available:

不幸的是,Boa似乎没有任何类型的mod_rewrite选项可供使用,所以你可以做的就是重写URL。从boa文档中可以找到您可以使用的选项:

Redirect, Alias, and ScriptAlias

重定向,别名和ScriptAlias

Redirect, Alias, and ScriptAlias all have the same semantics -- they match the beginning of a request and take appropriate action. Use Redirect for other servers, Alias for the same server, and ScriptAlias to enable directories for script execution.

Redirect,Alias和ScriptAlias都具有相同的语义 - 它们匹配请求的开头并采取适当的操作。将Redirect用于其他服务器,将Alias用于同一服务器,使用ScriptAlias为目录执行脚本。

Redirect

allows you to tell clients about documents which used to exist in your server's namespace, but do not anymore. This allows you tell the clients where to look for the relocated document.

允许您告诉客户有关服务器命名空间中曾经存在的文档,但不再这样做了。这允许您告诉客户端在哪里查找重定位文档。

Alias

aliases one path to another. Of course, symbolic links in the file system work fine too.

别名一条路径到另一条路径。当然,文件系统中的符号链接也可以正常工作。

ScriptAlias

maps a virtual path to a directory for serving scripts.

将虚拟路径映射到用于提供脚本的目录。

Based on that you might try ScriptAlias or Alias, or even a symlink to a "nicer" URL. Unfortunately since I don't have Boa available here I can't test the options to tell you more specifically what to try.

基于此,您可以尝试ScriptAlias或Alias,甚至是符号链接到“更好”的URL。不幸的是,因为我没有在这里提供Boa,所以我无法测试选项,更具体地告诉您要尝试什么。

#2


In apache, this would be simple with mod_rewrite, but boa is a little different. You've got a couple of different issues going on here. For the .html files make sure you have the following line in boa.conf:

在apache中,这对于mod_rewrite来说很简单,但是boa有点不同。你在这里遇到了几个不同的问题。对于.html文件,请确保boa.conf中包含以下行:

DirectoryIndex /index.html

Then any file that is called index.html will be retrieved when hitting the root. So if your root directory is /htdocs then makings /htdocs/index.html and /htdocs/info/index.html should take care of those problems.

然后在命中root时将检索任何名为index.html的文件。因此,如果您的根目录是/ htdocs,那么makings /htdocs/index.html和/htdocs/info/index.html应该处理这些问题。

For your other scripts, you'll need to add the following line:

对于其他脚本,您需要添加以下行:

AddType application/x-httpd-cgi pl

AddType application / x-httpd-cgi pl

That should let perl execute as CGIs execute everywhere. Then it's a matter of making sure that boa knows they're the index files. You may be able to get over some of that using Redirect or Alias directives.

这应该让perl在CGI执行时执行。然后是确保boa知道它们是索引文件的问题。您可以使用Redirect或Alias指令来克服其中一些问题。

#1


Boa unfortunately doesn't appear to have any type of mod_rewrite options available to it, so you're limited in what you can do to rewrite a URL. From the boa docs here are the options you do have available:

不幸的是,Boa似乎没有任何类型的mod_rewrite选项可供使用,所以你可以做的就是重写URL。从boa文档中可以找到您可以使用的选项:

Redirect, Alias, and ScriptAlias

重定向,别名和ScriptAlias

Redirect, Alias, and ScriptAlias all have the same semantics -- they match the beginning of a request and take appropriate action. Use Redirect for other servers, Alias for the same server, and ScriptAlias to enable directories for script execution.

Redirect,Alias和ScriptAlias都具有相同的语义 - 它们匹配请求的开头并采取适当的操作。将Redirect用于其他服务器,将Alias用于同一服务器,使用ScriptAlias为目录执行脚本。

Redirect

allows you to tell clients about documents which used to exist in your server's namespace, but do not anymore. This allows you tell the clients where to look for the relocated document.

允许您告诉客户有关服务器命名空间中曾经存在的文档,但不再这样做了。这允许您告诉客户端在哪里查找重定位文档。

Alias

aliases one path to another. Of course, symbolic links in the file system work fine too.

别名一条路径到另一条路径。当然,文件系统中的符号链接也可以正常工作。

ScriptAlias

maps a virtual path to a directory for serving scripts.

将虚拟路径映射到用于提供脚本的目录。

Based on that you might try ScriptAlias or Alias, or even a symlink to a "nicer" URL. Unfortunately since I don't have Boa available here I can't test the options to tell you more specifically what to try.

基于此,您可以尝试ScriptAlias或Alias,甚至是符号链接到“更好”的URL。不幸的是,因为我没有在这里提供Boa,所以我无法测试选项,更具体地告诉您要尝试什么。

#2


In apache, this would be simple with mod_rewrite, but boa is a little different. You've got a couple of different issues going on here. For the .html files make sure you have the following line in boa.conf:

在apache中,这对于mod_rewrite来说很简单,但是boa有点不同。你在这里遇到了几个不同的问题。对于.html文件,请确保boa.conf中包含以下行:

DirectoryIndex /index.html

Then any file that is called index.html will be retrieved when hitting the root. So if your root directory is /htdocs then makings /htdocs/index.html and /htdocs/info/index.html should take care of those problems.

然后在命中root时将检索任何名为index.html的文件。因此,如果您的根目录是/ htdocs,那么makings /htdocs/index.html和/htdocs/info/index.html应该处理这些问题。

For your other scripts, you'll need to add the following line:

对于其他脚本,您需要添加以下行:

AddType application/x-httpd-cgi pl

AddType application / x-httpd-cgi pl

That should let perl execute as CGIs execute everywhere. Then it's a matter of making sure that boa knows they're the index files. You may be able to get over some of that using Redirect or Alias directives.

这应该让perl在CGI执行时执行。然后是确保boa知道它们是索引文件的问题。您可以使用Redirect或Alias指令来克服其中一些问题。