使用IIS的重写URL将所有Cold Fusion CFM页面移动到ASP aspx页面

时间:2023-01-09 03:30:05

I am moving a large database driven website from coldfusion .cfm to .net aspx. I am pretty much finished now, but I need to do 301 redirects on all the coldfusion pages to the new aspx ones, so google and such like as we don't want to lose the search engine positioning. So I intended to use URL Rewrite for this, but I cannot get it working, most of the time I just get 404s back.

我正在将一个大型数据库驱动的网站从coldfusion .cfm移动到.net aspx。我现在已经完成了,但是我需要在所有的coldfusion页面上进行301重定向到新的aspx,所以google等我们不想失去搜索引擎定位。所以我打算使用URL Rewrite来实现这一点,但是我无法让它工作,大多数时候我只是回到了404。

Basically, my new aspx pages are all the same filename, just .cfm is replaced with .aspx, some pages can have a long querystring after them and some not.

基本上,我的新aspx页面都是相同的文件名,只有.cfm替换为.aspx,有些页面可以有一个很长的查询字符串,有些页面没有。

Examples:

http://www.example.com/test.cfm needs to be remapped to http://www.example.com/test.aspx

需要将http://www.example.com/test.cfm重新映射到http://www.example.com/test.aspx

http://www.example.com/test2.cfm?a=1&b=2&c=3 needs to be remapped to http://www.example.com/test2.aspx?a=1&b=2&c=3

需要将http://www.example.com/test2.cfm?a=1&b=2&c=3重新映射到http://www.example.com/test2.aspx?a=1&b=2&c=3

The site itself has hundreds of pages and some pages have over 8 variables in the querystring, so I just wanted to try and do a straight map over in URL rewrite. I cannot do a rule per page as that will take ages!

该网站本身有数百个页面,一些页面在查询字符串中有超过8个变量,所以我只是想在URL重写中尝试直接映射。我不能每页都做一个规则因为这需要很长时间!

My current attempt is:

我目前的尝试是:

<rule name="redirect all requests" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{URL}" pattern="^http://www.example.com/(.*).cfm(.*)$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{C:1}.aspx" appendQueryString="true" logRewrittenUrl="true" />
</rule>

This just does a 404 for me. Obviously the cfm pages do not exist and the aspx ones now do. I still have cold fusion installed on the server for now, and do not want to uninstall it until google has updated itself (it case of issues so I can always go back).

这对我来说只是404。显然cfm页面不存在,现在aspx页面也存在。我现在仍然在服务器上安装了冷融合,并且在google自我更新之前不想卸载它(如果出现问题,我可以随时返回)。

Any help would be much appreciated.

任何帮助将非常感激。

Thanks

David

2 个解决方案

#1


0  

It's like this...

就像这样...

<rule name="CFM301ASP" stopProcessing="true">
    <match url="^(.*)$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" pattern="^.*\.cfm$" negate="false" ignoreCase="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
    </conditions>
    <action type="Redirect" url="/yourfile.aspx" appendQueryString="true" redirectType="Permanent" />
</rule>

This only works on CFMs that do not exist (isFile=false). It will 301 redirect CFMs that would cause a 404, to your ASP file, and append the URL variables.

这仅适用于不存在的CFM(isFile = false)。它将301重定向将导致404的CFM到您的ASP文件,并附加URL变量。

#2


0  

The documentation seems to cover all of this.

文档似乎涵盖了所有这些。

From the docs on HTTP Redirect:

从HTTP重定向上的文档:

<configuration> <system.webServer> <httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found"> <add wildcard="*.php" destination="/default.htm" /> </httpRedirect> </system.webServer> </configuration>

< /system.webServer>

This led me to believe that you should be able to map URLs from one file extenstion to another.

这使我相信您应该能够将URL从一个文件扩展映射到另一个文件扩展。

Creating Rewrite Rules for the URL Rewrite Module

为URL重写模块创建重写规则

<rewrite> <rules> <rule name="Rewrite to article.aspx"> <match url="^article/([0-9]+)/([_0-9a-z-]+)" /> <action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}" /> </rule> </rules> </rewrite>

< action type =“Rewrite”url =“article.aspx?id = {R:1}& title = {R:2}”/>

Try reading through these docs, you should be able to find the correct syntax that will allow you to just transfer from *.cfm to *.aspx, passing along the same query strings, or making translations as needed.

尝试阅读这些文档,您应该能够找到正确的语法,允许您从* .cfm转移到* .aspx,传递相同的查询字符串,或根据需要进行翻译。

#1


0  

It's like this...

就像这样...

<rule name="CFM301ASP" stopProcessing="true">
    <match url="^(.*)$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" pattern="^.*\.cfm$" negate="false" ignoreCase="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
    </conditions>
    <action type="Redirect" url="/yourfile.aspx" appendQueryString="true" redirectType="Permanent" />
</rule>

This only works on CFMs that do not exist (isFile=false). It will 301 redirect CFMs that would cause a 404, to your ASP file, and append the URL variables.

这仅适用于不存在的CFM(isFile = false)。它将301重定向将导致404的CFM到您的ASP文件,并附加URL变量。

#2


0  

The documentation seems to cover all of this.

文档似乎涵盖了所有这些。

From the docs on HTTP Redirect:

从HTTP重定向上的文档:

<configuration> <system.webServer> <httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found"> <add wildcard="*.php" destination="/default.htm" /> </httpRedirect> </system.webServer> </configuration>

< /system.webServer>

This led me to believe that you should be able to map URLs from one file extenstion to another.

这使我相信您应该能够将URL从一个文件扩展映射到另一个文件扩展。

Creating Rewrite Rules for the URL Rewrite Module

为URL重写模块创建重写规则

<rewrite> <rules> <rule name="Rewrite to article.aspx"> <match url="^article/([0-9]+)/([_0-9a-z-]+)" /> <action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}" /> </rule> </rules> </rewrite>

< action type =“Rewrite”url =“article.aspx?id = {R:1}& title = {R:2}”/>

Try reading through these docs, you should be able to find the correct syntax that will allow you to just transfer from *.cfm to *.aspx, passing along the same query strings, or making translations as needed.

尝试阅读这些文档,您应该能够找到正确的语法,允许您从* .cfm转移到* .aspx,传递相同的查询字符串,或根据需要进行翻译。