Iis 重定向除少数目录/路径之外的所有web流量?
我有一个网站,我需要重定向几乎所有的东西到另一个域,除了一些目录/路径。服务器正在宿主环境中运行ColdFusion和IIS 功能:Iis 重定向除少数目录/路径之外的所有web流量?,iis,coldfusion,windows-server,Iis,Coldfusion,Windows Server,我有一个网站,我需要重定向几乎所有的东西到另一个域,除了一些目录/路径。服务器正在宿主环境中运行ColdFusion和IIS 功能: a) http://example1.com redirects to http://example2.com b) http://example1.com/special stays put c) http://example1.com/anydir redirects to http://example2.com 对我如何完成这一点有什么建议吗 我曾考虑过在
a) http://example1.com redirects to http://example2.com
b) http://example1.com/special stays put
c) http://example1.com/anydir redirects to http://example2.com
对我如何完成这一点有什么建议吗
我曾考虑过在ColdFusion中这样做,但这无法处理案例c)。无法在IIS中重写URL,因为这是宿主提供程序中的一个限制
编辑:
我刚刚意识到上述功能并没有明确说明这种情况:
d) http://example1.com/anydir/anydir redirects to http://example2.com
如果可以的话,您最好使用服务器来处理重定向,但是如果可以的话,您可以使用CF这样做。。您的结构实际上取决于您需要处理的实际URL 您可能会用正则表达式处理case(c)
<!---get the current URL--->
<cfset currentURL = "#cgi.server_name##cgi.path_info#" >
<!---based on the URL, redirect accordingly--->
<cfif FindNoCase("example1.com/special", currentURL)>
<!---do nothing--->
<cfelseif FindNoCase("example1.com", currentURL)>
<cflocation url="http://www.example2.com" >
</cfif>
不久前,我创建了这个应用程序,以将现有应用程序从旧路径重定向到新路径。我相信它依赖于子文件夹的存在,例如“anydir/anydir/”实际上必须是真实的文件夹。我基本上只是将其粘贴到现有的应用程序文件夹中,以便覆盖配置、应用程序和索引文件,然后根据配置中的定义进行重定向 重定向定义是正则表达式,因此在必要时可能会变得非常复杂。它是一个有序数组,因此您可以先放置更具体的重定向,然后在最后放置更一般的重定向。您可以在末尾包含“最后手段”重定向,也可以在定义不匹配的情况下允许发生错误——这取决于您希望的精确程度 config/config.cfm Application.cfc
#新路径#
我试图在Application.cfm中添加一个变体,以便始终对其进行处理,以确保除排除的请求外,所有请求都得到转发。然而,它没有起作用。Application.cfm不是一个合适的地方吗?Application.cfm是一个很好的地方。。要确保它正在运行,只需在块的上方和下方输出一些标签,以查看它们是否正在输出。。。。尝试输出#currentURL#以查看其内容。。玩弄它。。它应该有用。。
<cfset config = {
debug=true
, redirects = [
{find="^/path/temp/dir2/(.+)$", replace="http://temp.domain.com/dir2\1"}
, {find="^/path/temp/(.+)$", replace="http://temp.domain.com/\1"}
]
} />
[blank file]
<cfcomponent>
<cfset this.name="Redirect#hash(getCurrentTemplatePath())#"/>
<cfinclude template="config/config.cfm" />
<cffunction name="onRequestStart">
<cfset redirect(cgi.path_info) />
</cffunction>
<cffunction name="onMissingTemplate">
<cfargument name="targetPage" required="true" />
<cfset redirect(arguments.targetPage) />
</cffunction>
<cffunction name="redirect">
<cfargument name="targetPage" required="true" />
<cfset var i = 0 />
<cfset var newpath = "" />
<cfloop from="1" to="#arraylen(variables.config.redirects)#" index="i">
<cfif refindnocase(variables.config.redirects[i].find, arguments.targetPage)>
<cfset newpath = rereplacenocase(arguments.targetPage, variables.config.redirects[i].find, variables.config.redirects[i].replace) />
<cfif len(cgi.query_string)>
<cfset newpath &= "?" & cgi.query_string />
</cfif>
<cfif variables.config.debug>
<cfoutput>#newpath#</cfoutput>
<cfabort>
</cfif>
<cflocation url="#newpath#" addtoken="false" />
</cfif>
</cfloop>
<cfthrow type="custom.redirect.notfound" />
<cfabort>
</cffunction>
</cfcomponent>