【问题标题】:IIS URL RewriteIIS URL 重写
【发布时间】:2016-06-27 19:25:58
【问题描述】:

我有以下重写规则:

    <rewrite>
        <rules>
            <rule name="FrontController" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                </conditions>
                <action type="Rewrite" url="wcf/api.svc/auth/home" />
            </rule>
        </rules>
    </rewrite>

这基本上将所有非文件 url 重写为 Web 服务 api 调用,该调用在 WCF 支持的 SPA 中返回 index.html。

上述重写最终包括原始 URL 中包含的所有查询字符串参数。我需要做的是将原始URL,例如'wcf/api.svc/auth/products'作为查询字符串参数包含在重写的URL中,例如'https://domain.com/wcf/api.svc/auth/products?enc=lkjewro8xlkz'被转换为'@987654322 @'。

这可能吗?如果可以,我需要做出哪些改变来实现它?我希望我的 WCF 应用程序知道原始 URL,以便它可以配置 SPA 以在加载时初始化为特定视图。

谢谢

【问题讨论】:

    标签: wcf iis url-rewrite-module


    【解决方案1】:

    很有可能。

    您需要将{REQUEST_URI}URL Encoded 值添加到重写URL。

    <rewrite>
        <rules>
            <rule name="FrontController" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                </conditions>
                <action type="Rewrite" url="wcf/api.svc/auth/home?orig={UrlEncode:{REQUEST_URI}}" />
            </rule>
        </rules>
    </rewrite>
    

    使用此规则,在您的 WCF 端点中,orig 参数将是:

    /wcf/api.svc/auth/products?enc=lkjewro8xlkz
    

    如果您不想要查询字符串部分 (?enc=lkjewro8xlkz),则需要一个额外的条件来匹配没有查询字符串的 URI。

    <rewrite>
        <rules>
            <rule name="FrontController" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    
                    <!-- match any character up to a question mark -->
                    <add input="{REQUEST_URI}" pattern="^[^\?]+" />
                </conditions>
    
                <!-- {C:0} means the first match in conditions -->
                <action type="Rewrite" url="wcf/api.svc/auth/home?orig={UrlEncode:{C:0}}" />
            </rule>
        </rules>
    </rewrite>
    

    现在,orig 将是 WCF 端点中的 /wcf/api.svc/auth/products

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2013-07-01
      • 2013-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多