两个不同服务器上的标准链接 - 不同的行为

时间:2012-10-30 21:49:32

标签: asp.net html iis hyperlink relative-path

我找不到这个帖子的更好的标题,但我希望它有意义。

我有两台Windows服务器:

  1. 共享托管,在子域(test.domain.com)上托管我的测试网站。 Windows Server 2008 R2
  2. 使用Windows Server 2008的云服务器。我有IIS访问权限
  3. 在我的第一个案例中,我刚刚使用FTP上传了该应用程序。在我的第二个案例中,我像往常一样设置了IIS。

    在我的内容中,我有几个链接形成如下:

    <a href="Mylink/">Text</a>
    

    MyLink通过URL路由引导页面。但是,假设链接位于某个子页面上,例如domain.com/MySubpage,会发生这种情况:

    服务器2的行为:

    domain.com/MySubpage/MyLink/
    

    服务器1的行为:

    domain.com/MyLink/
    

    问题是,我需要云服务器上服务器1的行为。我的数据库中有很多文章,我不能轻易更改链接,所以必须有一些简单的方法来设置行为1?

    我该如何解决?

1 个答案:

答案 0 :(得分:0)

似乎URL Anri posted,问题是如何对待网址。服务器#1认为它不是字典,而#2则是。

我将此代码添加到我的web.config中,一切都解决了:

 <rewrite>
      <rules>

        <!--To always remove trailing slash from the URL-->
        <rule name="Remove trailing slash" stopProcessing="true">
          <match url="(.*)/$"/>
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="{R:1}"/>
        </rule>
      </rules>
    </rewrite>

因为出于搜索引擎优化的原因,我想要这种行为,它没有任何不幸的问题。

相关问题