【问题标题】:Helicon Tech - ISAPI_Rewrite: RewriteRule's for specific domainsHelicon Tech - ISAPI_Rewrite:特定域的 RewriteRule
【发布时间】:2010-08-12 15:05:56
【问题描述】:

谁能帮我把下面的伪代码翻译成Helicon Tech's ISAPI_Rewrite module能理解的代码:

if (domain == something.com OR domain == www.something.com)
{
    // The rules inside this scope will only apply to the domain:
    // something.com / www.something.com

    // This should match "something.com/test" and/or "www.something.com/test"
    RewriteRule /something /something/something.aspx
}


if (domain == test.com OR domain == www.test.com)
{
    // The rules inside this scope will only apply to the domain:
    // test.com / www.test.com

    // This should match "test.com/test" and/or "www.test.com/test"
    RewriteRule /test /test/test.aspx
}

documentation 让我很困惑。

非常感谢任何和所有帮助。

【问题讨论】:

    标签: url-rewriting


    【解决方案1】:

    如果 ISAPI_Rewrite 的工作方式与 Apache 的 mod_rewrite 相同,试试这个:

    RewriteCond %{HTTP_HOST} ^(www\.)?something\.example$
    RewriteRule ^/something$ /something/something.aspx
    
    RewriteCond %{HTTP_HOST} ^(www\.)?test\.example$
    RewriteRule ^/test$ /test/test.aspx
    

    注意:我根据RFC 2606使用了其他域名。


    编辑:似乎对于 ISAPI_Rewrite,您必须将 %{HTTP_HOST} 替换为 Host: 才能获取当前主机。

    【讨论】:

      【解决方案2】:

      这是版本 3 之前使用的“旧”语法:

      RewriteCond Host: ^(www\.)?something\.com$
      RewriteRule ^/something$ /something/something.aspx
      
      RewriteCond Host: ^(www\.)?something\.com$
      RewriteRule ^/test$ /test/test.aspx
      

      这将是版本 3 及更高版本的新语法。这更接近于 mod_rewrite:

      RewriteCond %{HTTP:Host} ^(www\.)?something\.com$
      RewriteRule ^/something$ /something/something.aspx
      
      RewriteCond %{HTTP:Host} ^(www\.)?something\.com$
      RewriteRule ^/test$ /test/test.aspx
      

      两个版本的正则表达式本身是相同的。

      【讨论】:

      • 我认为新的语法应该是 %{HTTP_HOST} (下划线而不是冒号)。
      • 这是他们自己的语法转换器工具给我的。
      • 没那么快:%{HTTP:Host} 访问原始标头,而 %{HTTP_HOST} 访问服务器变量。并非每个标头都有相应的服务器变量,但在这种情况下,它们都应该包含相同的值。 (我相信 mod_rewrite 根本无法访问标题。)
      【解决方案3】:

      请注意,ISAPI 3 轻量版不支持上述 per-directory httpd.ini 方法:http://www.helicontech.com/isapi_rewrite/doc/litever.htm

      【讨论】:

        【解决方案4】:

        感谢 Gumbo 和 Tomalak 的努力。真的很感激。

        不过,我已经找到了另一种方法:您将一个文件 (httpd.ini) 包含特定的重写内容,放在该虚拟目录/域的根文件夹中的特定虚拟目录/域中。

        这也消除了对全局配置文件的污染。

        【讨论】:

        • 这与您的问题有什么关系? :-)
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多