【问题标题】:Using IIS Rewrite URL for SEO to move all Cold Fusion CFM pages to ASP aspx pages使用用于 SEO 的 IIS 重写 URL 将所有 Cold Fusion CFM 页面移动到 ASP aspx 页面
【发布时间】:2017-03-08 19:18:41
【问题描述】:

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

基本上,我的新aspx页面都是相同的文件名,只是将.cfm替换为.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需要重新映射到http://www.example.com/test2.aspx?a=1&b=2&c=3

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

我目前的尝试是:

<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>

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

任何帮助将不胜感激。

谢谢

大卫

【问题讨论】:

  • IIS 404 页面不命名它尝试加载的文件吗?!?

标签: asp.net iis url-rewriting coldfusion iis-8.5


【解决方案1】:

是这样的……

<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>

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

【讨论】:

    【解决方案2】:

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

    来自HTTP Redirect 上的文档:

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

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

    Creating Rewrite Rules for the URL Rewrite Module

    <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>

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

    【讨论】:

    • 这个例子没有重定向,它是一个重写。而且它不会保留所有 url 变量。
    猜你喜欢
    • 1970-01-01
    • 2011-02-16
    • 2019-09-08
    • 2014-10-04
    • 2012-06-16
    • 2012-05-15
    • 1970-01-01
    • 2015-12-10
    • 1970-01-01
    相关资源
    最近更新 更多