用IIS使用ColdFusion重写URL
我已经做了一些搜索,但不能把它放在一起。这是我需要:用IIS使用ColdFusion重写URL
我想有人冲浪:
www.mysite.com/thisPlace
,并会将其重定向到
www.mysite.com/template .CFM?PM = MS & loc_id = 4
要做到这一点,我莫名其妙地需要捕捉,他们没有在他们的HTTP请求申请的现有文件并运行程序查询记录在数据库中的网页.CFM locationName ='thisPlace'然后重定向t下摆页面像 template.cfm?PM = MS & loc_id = 4,其中4是匹配该行的记录ID“thisPlace”
如果IIS默认文档设置为index.cfm
,你可以创建一个称为“thisPlace”的文件夹(目录),并放置一个index.cfm文件,该文件只包含一个<cflocation>
标记和随附的查询/逻辑来计算URL。
Website.com/thisPlace会按照您的描述运行。
编辑:
你可以添加自定义的404页...
使它成为一个.CFM文件,而不是HTML。扫描模板路径以查看用户正在查找的内容。如果您在数据库中找到它,请将它们重定向到那里,否则将它们重定向到一般的404页面。
<!---Up to a certain point (the directory in which you store your code) this will always be the same so you can hard-code your number --->
<cfset QueryConstant = #LEFT(CGI.CF_Template_Path, 22)#>
<!---Find the overall length of the template path. --->
<cfset QueryVariable = #Len(CGI.CF_Template_Path)#>
<!---Take whatever is past your QueryConstant (AKA the string that produces a 404 error.) --->
<cfset theRightNumber = QueryVariable - 22>
<cfset QuerySearchString = #RIGHT(CGI.CF_Template_Path, theRightNumber)#>
<cfquery name="ListOfLocations" datasource="CRM">
SELECT TOP 1 LocationID
FROM LocationTable
WHERE LocationName LIKE '%#QuerySearchString#%'
</cfquery>
<cfif ListOfLocations.recordcount>
<cflocation url="/SomePage.cfm?LocationID=#ListOfLocations.LocationID#">
<cfelse>
<cflocation url="/Regular404page.html">
</cfif>
谢谢你们!巨大的帮助!使用您的投入,这是我做的: (不得不用QUERY_STRING,而不是CF_Template_Path,作为CF_Template_Path没有沿着任何自定义错误页的URL后传
我建立了一个自定义404错误在IIS执行URL。 。到一个名为check404error.cfm文件
当有人查找www.example.com/thisPlace,IIS把他们http://www.example.com/check404error.cfm我使用CGI.QUERY_STRING(404; http://www.example.com:443/thisPlace),最终获得“thisPlace”字符串与搜索。
<!---Up to a certain point (the directory in which you store your code) this will always be the same so you can hard-code your number --->
<cfset QueryConstant = #LEFT(CGI.QUERY_STRING, 31)#>
<!---Find the overall length of the template path. --->
<!---31 is the length of '404;http://www.example.com:443/' --->
<cfset QueryVariable = #Len(CGI.QUERY_STRING)#>
<!---Take whatever is past your QueryConstant (AKA the string that produces a 404 error.) --->
<cfset theRightNumber = QueryVariable - 31>
<cfset QuerySearchString = #RIGHT(CGI.QUERY_STRING, theRightNumber)#>
<cfquery name="ListOfLocations" datasource="#request.dsn#">
\t SELECT location.id
\t FROM location WHERE url_name = <cfqueryparam value="#QuerySearchString#" cfsqltype="CF_SQL_VARCHAR" maxlength="255"> LIMIT 1
</cfquery>
<cfif ListOfLocations.recordcount>
\t <cflocation url="https://example.com/template.cfm?pm=ms&loc_id=#ListOfLocations.id#" addtoken="no" statusCode="301">
<cfelse>
\t <cflocation url="/404error.cfm" addtoken="no">
</cfif>
这是最流行的MVC框架今天的工作,通过解析出网段。
您有权访问任何类型的URL重写软件吗?
由于您使用的是IIS,因此它具有内置的重写引擎,您可以简单地将这些请求重写为已知文件,从而节省了发送404回复和解析的开销,并且创建了更多请求那个。
查看http://wiki.coldbox.org/wiki/URLMappings.cfm了解详情。我们使用ISAPI重写版本版本做你所要求的只是什么
- 为www.mysite.com/thisPlace接收请求
- thisPlace不是目录
- thisPlace不是文件
- 重新发送到index.cfm或您选择的位置以进行额外的解析
- Helicon Rewrite发送名为HTTP_X_REWRITE_URL的HTTP标头,并将原始请求的URL解析出来,这非常简单。
这一切发生在一个请求内联,因此客户端从不重定向。
为什么这个标签为'PHP'? – CD001
不知道,我提交时没有看到它。对不起,我删除了它。 –