Iis 7 IIS将.html URL重写为ColdFusion-如何获取查询字符串?
我正在接管一个ColdFusion应用程序,重写时遇到了一些问题 该站点位于IIS7/CF9.0.1/SQL Server堆栈上。Helicon经理正在处理重写 大多数URL都被写入html文件,因此我们有类似于/profile.html的内容 URL被以下行重写:Iis 7 IIS将.html URL重写为ColdFusion-如何获取查询字符串?,iis-7,coldfusion,url-rewriting,Iis 7,Coldfusion,Url Rewriting,我正在接管一个ColdFusion应用程序,重写时遇到了一些问题 该站点位于IIS7/CF9.0.1/SQL Server堆栈上。Helicon经理正在处理重写 大多数URL都被写入html文件,因此我们有类似于/profile.html的内容 URL被以下行重写: RewriteRule /([^\?]*?)\.(html)(\??)(.*)? /default.cfm?name=$1.$2&$4 [I] 当存在像/view.html?id=123这样的查询字符串时,就会出现问题。查
RewriteRule /([^\?]*?)\.(html)(\??)(.*)? /default.cfm?name=$1.$2&$4 [I]
当存在像/view.html?id=123这样的查询字符串时,就会出现问题。查询字符串应该由$4变量编写,但当我像这样转储URL时,我在应用程序中从未得到任何东西:
<cfset objRequest = GetPageContext().GetRequest() />
<cfset strUrl = objRequest.GetRequestUrl().Append(
"?" & objRequest.GetQueryString()
).ToString()
/>
<cfoutput>#strUrl#</cfoutput>
#斯特鲁尔#
我得到了类似:。查询字符串从未显示
我相信这是一个IIS设置-允许.html处理程序访问获取变量?我已经设置了一个.html处理程序,但运气不好。这不起作用的原因是RewriteRule从未看到查询字符串,只看到资源的路径。要访问查询字符串,需要使用重写条件
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([^\.]+)\.html$ default.cfm?name=$1.html&%1 [NC,L]
在本例中,我们只是检查查询字符串,并使用%1
,这意味着RewriteCond
中的第一个组。在您的示例中,这是过分的,您不需要匹配任何内容,就可以这样做:-
RewriteEngine on
RewriteBase /
RewriteRule ^([^\.]+)\.html$ default.cfm?name=$1.html&%{QUERY_STRING} [NC,L]
然而,聪明的方法只是使用正确的标志来做你想做的事情,这就是QSA
,这意味着查询字符串附加如下:-
RewriteEngine on
RewriteBase /
RewriteRule ^([^\.]+)\.html$ default.cfm?name=$1.html [NC,QSA,L]
Helicon的ISAPI重写的所有文档都可以在此处找到:。他们很容易把它们做成书签
我希望这会有所帮助。这不起作用的原因是RewriteRule从未看到查询字符串,只看到资源的路径。要访问查询字符串,需要使用重写条件
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^([^\.]+)\.html$ default.cfm?name=$1.html&%1 [NC,L]
在本例中,我们只是检查查询字符串,并使用%1
,这意味着RewriteCond
中的第一个组。在您的示例中,这是过分的,您不需要匹配任何内容,就可以这样做:-
RewriteEngine on
RewriteBase /
RewriteRule ^([^\.]+)\.html$ default.cfm?name=$1.html&%{QUERY_STRING} [NC,L]
然而,聪明的方法只是使用正确的标志来做你想做的事情,这就是QSA
,这意味着查询字符串附加如下:-
RewriteEngine on
RewriteBase /
RewriteRule ^([^\.]+)\.html$ default.cfm?name=$1.html [NC,QSA,L]
Helicon的ISAPI重写的所有文档都可以在此处找到:。他们很容易把它们做成书签
我希望这有帮助