【问题标题】:Problem with URL rewrite of host-header主机标头的 URL 重写问题
【发布时间】:2009-08-19 10:30:10
【问题描述】:

我正在尝试在我的主/根网站上使用ManagedFusion UrlRewriter 模块将具有特定主机名的请求重定向到根的子文件夹。假设我的根名为profkroot.com,它有一个名为cottages 的子文件夹(ASP.NET 应用程序)。我还有一个名为profkcottages.com 的域,我正在尝试将其重定向到profkroot.com/cottages

使用以下示例规则,我得到了一个完全无聊的重写 URL。我了解规则的正则表达式方面,但我对重写部分的了解不够,而且这变得有点紧迫,所以任何帮助将不胜感激。

这是profkroot.com 上的规则: 重写引擎开启

#Fix missing trailing slash char on folders
RewriteCond %{HTTP:Host} (.*)
RewriteRule ([^.?]+[^.?/]) http\://%1$1/ [R]

#Emulate profkcottages.com
RewriteCond %{HTTP:Host} (?:www\.)?profkcottages\.com
RewriteRule (.*) /cottages$1 [NC,L]

如果我请求http://profcottages/home.aspx,这是重写的网址:

http://profkcottages.com/http/://profkcottages.com/home/.http/://profkcottages.comaspx/

【问题讨论】:

    标签: asp.net mod-rewrite url-rewriting


    【解决方案1】:

    CSS 和图像内容很简单,您的规则没有正确处理它们。

    【讨论】:

    • 好的,关于为什么规则没有正确处理它们的任何提示?
    • 几个原因,您可能正在为您的图像和 CSS 使用相对 URL,这是最可能的原因。第二个是您的图像内容以与请求它们相同的方式存在于 Cottages 目录中。尝试启用日志记录 RewriteLog "log.txt" RewriteLogLevel 9 并查看 URL 与图像一样。
    【解决方案2】:

    原来我添加了两次RewriterModule;一次在System.Web 下,用于IIS6(托管),一次在System.WebServer 下,用于IIS7(本地)。仍然不能 100% 使用 css 和 img 内容,但这是另一个问题。

    【讨论】:

      猜你喜欢
      • 2013-03-04
      • 2020-04-10
      • 2020-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多