iis-7 - 在 IIS7 中重定向到 www - 经典管道模式

标签 iis-7 redirect seo

我想在 IIS7 网络服务器上实现重定向。基本上,如果 URL 中不包含子域,我将重定向到 www 子域。

http://mysite.com/file.aspx重定向到 http://www.mysite.com/file.aspx

http://mysite.com/image.jpg重定向到 http://www.mysite.com/image.jpg

http://mysite.com/text.html重定向到 http://www.mysite.com/text.html

如何做到这一点?

我不想编写任何 HTTP 模块——它只能通过 IIS 配置完成。

此外,我需要使用经典管道模式并且不能安装任何 ISAPI 插件。

这可能吗?

最佳答案

您可以将其放入您的 web.config 文件中:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^http://mysite.com$" />
          </conditions>
          <action type="Redirect" url="http://www.mysite.com/{R:0}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

在 IIS7 中,它可以通过 url 重写部分来完成。

关于iis-7 - 在 IIS7 中重定向到 www - 经典管道模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4445285/

相关文章:

网址 : Files and Directories with the same name?

html - 使用 JWplayer 加载文件媒体时出错,无法播放

asp.net - 在 ASP.net Web 应用程序中检索 COM 类工厂的异常

ruby-on-rails - 在 Rails 中呈现不同的格式/布局如何影响 SEO?

php - 如何使 Prestashop 404 错误页面重定向到主页,而不是默认模板?

ssl - 如何将一个域重定向到另一个包含路径的域(使用 DNS)?

html - Cookie 免费域 : Subdomain Alternative

c# - wcf 客户端 ip 作为 ipv6

c# - 使用 Web 应用程序管理定时事件的首选方法是什么?

php - Laravel Socialite - 在重定向之前保存 URL