ColdFusion 10 + IIS:作为 CFM 文件的不存在的 URL.执行 404 页面后检索原始 URL [英] ColdFusion 10 + IIS: Non-existant URLs that are CFM files. Retrieving original URL after executing 404 page

查看:19
本文介绍了ColdFusion 10 + IIS:作为 CFM 文件的不存在的 URL.执行 404 页面后检索原始 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的服务器设置如下:

We have a server setup as follows:

  • Windows 2012 R2
  • Coldfusion 10,企业版
  • IIS,配置自定义 404 页面(在服务器上执行)

自定义 404 页面(一个 CFM 文件)处理丢失的 URL,并根据数据库中的自定义 URL 检查它们.如果找到匹配项,它将显示相关数据.当自定义 URL 映射到不存在的 CFM 文件时会出现问题;例如.

The custom 404 page (a CFM file) handles missing URLs and checks them against custom URLs in the database. If it finds a match, it will display the relevant data. The problem occurs when the custom URL maps to a non-existant CFM file; for example.

/home/map.cfm(不是真正的文件或目录)

/home/map.cfm (not a real file or directory)

现在,当用户请求此 URL 时,服务器会看到它是一个 CFM 文件并正确地将其传递给 ColdFusion(通过 ISAPI 重定向).Tomcat 看到这个文件实际上并不存在,并返回一个 404.IIS 看到这个 404 消息并执行自定义错误页面(/errors/404.cfm).

Now, when a user requests this URL, the server sees that it is a CFM file and correctly passes it to ColdFusion (via the ISAPI redirect). Tomcat sees that this file does not actually exist, and returns a 404. IIS sees this 404 message and executes the custom error page (/errors/404.cfm).

生成的 CGI 变量实际上不允许我们检索原始 URL(将其映射到数据库中的虚拟 URL),通常作为 CGI.QUERY_STRING 变量的一部分提供.相反,QUERY_STRING 变量包含jakarta"目录中isapi_rewrite.dll"文件的路径.

The resulting CGI variables do not infact allow us to retrieve the original URL (to map it to a virtual URL in the database), usually provided as part of the CGI.QUERY_STRING variable. Instead, the QUERY_STRING variable contains the path to the 'isapi_rewrite.dll' file, in the 'jakarta' directory.

在 Tomcat 为所述页面返回 404 错误后,有什么方法可以保留最初请求的(CFM 文件的)URL?

Is there any way to retain the originally requested URL (of a CFM file), after Tomcat has returned a 404 error for said page?

解决方案,由 Thomas Gorgolione 启发,由我自己编写

正如怀疑的那样,问题总是归结为请求被转发到 ISAPI_REDIRECT 模块,即使相关文件不存在.

As suspected, the issue invariably came down to the request being forwarded to the ISAPI_REDIRECT module, even if the file in question did not exist.

正如 Thomas 所建议的,一个优雅的解决方案是在将文件/目录传递给 ISAPI_REDIRECT 模块之前,利用重写来检查文件/目录是否确实存在.

As Thomas suggested, an elegant solution is to utilize rewrites to check that the file / directory actually exists, before passing it through to the ISAPI_REDIRECT module.

虽然 Thomas 建议的软件可以解决问题,但我无法将其安装在 64 位 Windows 2012 R2 机器上.但是,我设法回退到使用 IIS8(可能还有早期版本)中包含的 URL 重写模块.

While the software Thomas suggested would of done the trick, I was unable to get it to install on a 64bit Windows 2012 R2 machine. I've managed however to fall back to utilize the URL Rewrite module included with IIS8 (and possibly earlier versions).

请参阅下面提供解决方案的我的 web.config 条目.

See my web.config entry below that provides a solution.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpErrors>
            <remove statusCode="404" subStatusCode="-1" />
        </httpErrors>
        <rewrite>
            <rules>
                <rule name="404 HTTP">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{REQUEST_URI}" pattern="CFFileServlet/(.*)" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{SERVER_PORT_SECURE}" pattern="0" />
                    </conditions>
                    <action type="Rewrite" url="/404.cfm?404;http://{HTTP_HOST}:{SERVER_PORT}{REQUEST_URI}" />
                </rule>
                <rule name="404 HTTPS">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{REQUEST_URI}" pattern="CFFileServlet/(.*)" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{SERVER_PORT_SECURE}" pattern="1" />
                    </conditions>
                    <action type="Rewrite" url="/404.cfm?404;https://{HTTP_HOST}:{SERVER_PORT}{REQUEST_URI}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

上述配置文件同时考虑了 HTTP 和 HTTPS 请求.它还将考虑 CFFileServlet 目录,ColdFusion 使用该目录来托管临时图像和资产.如果 URL 以该目录开头,它将作为正常请求传递.

The above configuration file takes into account both HTTP and HTTPS requests. It will also take into account the the CFFileServlet directory, which ColdFusion uses to host temporary images and assets. If the URL starts with this directory, it will be passed on as a normal request.

感谢大家的意见.

推荐答案

注意:上述问题也包含解决方案.

我认为这是 Coldfusion 连接器的错误.我会向 Adob​​e (https://bugbase.adobe.com/) 发布错误报告.我确实有一个解决方法.我有同样的问题,但我使用 IIRF(离子 IIS 重定向器 - http://iirf.codeplex.com/),我找到了一种方法来使用它来避免现在的错误:

I think this is an error with the Coldfusion Connector. I would post a bug report to Adobe (https://bugbase.adobe.com/). I do have a workaround though. I have the same issue, but I use IIRF (Ionic IIS Redirector - http://iirf.codeplex.com/), and I found a way to use that to avoid the bug for now:

  1. 在 IIS/Coldfusion 中删除任何以前的 404 文件配置
  2. 按照 IIRF 的安装说明正常安装.
  3. 在 IirfGlobal.ini 文件(通常位于 C:WindowsSystem32inetsrvIIRF)中,添加以下行:

  1. Remove any previous 404 file configuration in IIS/Coldfusion
  2. Install IIRF normally, according to it's install instructions.
  3. In the IirfGlobal.ini file (normally located in C:WindowsSystem32inetsrvIIRF), add the following line:

RewriteFilterPriority HIGH

这将允许 IIRF 在到达 ColdFusion/Tomcat 之前处理 404 请求.

This will allow IIRF to handle 404 requests before it even hits ColdFusion/Tomcat.

在特定于站点的 Iirf.ini 中(通常您在 Web 文件的根文件夹中创建一个 - 请参阅 IIRF 文档了解详细信息),添加以下规则:

In the site-specific Iirf.ini (usually you create one in the root folder of your web files -- see the IIRF docs for details), add the following rules:

RewriteCond %{SCRIPT_TRANSLATED} !-f
RewriteCond %{SCRIPT_TRANSLATED} !-d
RewriteRule ^(.+)$ page_to_redirect_to.cfm?404;$1 [L]

这会将所有不存在的文件/目录重定向到page_to_redirect_to.cfm,并像往常一样添加404查询字符串.

That will redirect all files/directories that don't exist to page_to_redirect_to.cfm, and add the 404 query string like normal.

添加了以下步骤: 进入 IIS 管理器并选择配置为使用 IIRF 的服务器或网站,然后进入 ISAPI 过滤器部分.点击查看有序列表",然后将 IIRF 过滤器移至顶部.

Added a following step: Go into the IIS Manager and select either the server or the Web Site that was configured to use IIRF, then go into the ISAPI Filters section. Click on "View Ordered List", then move the IIRF filter up to the top.

编辑 2:刚刚向 Adob​​e 发布了一个错误.请参阅 https://bugbase.adobe.com/index.cfm?event=错误&id=3630245

EDIT 2: Just posted a bug to Adobe. See https://bugbase.adobe.com/index.cfm?event=bug&id=3630245

希望对您有所帮助.

这篇关于ColdFusion 10 + IIS:作为 CFM 文件的不存在的 URL.执行 404 页面后检索原始 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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