【问题标题】:Having a CGI script catch all requests to a domain with Apache让 CGI 脚本使用 Apache 捕获对域的所有请求
【发布时间】:2009-05-19 06:56:55
【问题描述】:
【问题讨论】:
标签:
apache
mod-rewrite
apache2
cgi
【解决方案1】:
RewriteEngine On
RewriteRule ^(.*)$ /cgi-bin/cgi.py?url=$1
这会将所有请求重定向到您的 python 文件。
如果您仍然遇到脚本别名问题,请尝试在 RewriteRule 行的末尾添加 passthrough 标志 [PT]
如果您仍然希望能够访问图像等,请在 RewriteRule 之前添加:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
【解决方案2】:
(不确定回答自己问题的正确程序 - 但是...)
看起来我与 ScriptAlias 和 RewriteRule 有冲突。最后的解决方案是使用 AddHandler 创建关系,然后使用 mod_rewrite 将所有内容拉入 CGI。和 RewriteCond 以避免捕获 /resources/ 和 /media/。我的 VirtualHost 现在看起来像这样:
AddHandler cgi-script .cgi
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/resources/.*$
RewriteCond %{REQUEST_URI} !^/media/.*$
RewriteRule ^(.*)$ /cgi-bin/pyblosxom.cgi$1 [L]
感谢你们的帮助。
【解决方案3】:
虽然它不是 100% 您正在寻找的东西,但这是我用于我的一个旧的废弃域的 .htaccess 以正确重定向人们。它基本上重定向本地目录结构中找不到的任何文件或目录。由脚本本身决定调用它的 url:
RewriteEngine On
#if the request isn't for a file or a directory...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
【解决方案4】:
我使用了捕获重写规则,它在一定程度上起作用。问题是请求 URI 的原始查询字符串在使用 $1 时没有传递给 cgi。我最终删除了捕获并仅在我的 cgi 脚本中引用 ENV['REQUEST_URI'] 以获得访问权限。