开发者

How do you override the Tuckey use-query-string setting?

I'm trying to add a query param to a redirected url like this in urlrewrite.xml:

<rule>
    <condition name="host">www.foo.com</开发者_Go百科condition>
    <from>^/foo/bar</from>
    <to type="redirect" last="true">http://www.bar.com/foo/bar?test=testString</to>
</rule>

But the request coming in has a param on it already and the resulting redirected url is this:

http://www.bar-d.mtvi.com/foo/bar?test=testString?test2=test2String

notice the 2nd "?".

What I want is this:

http://www.bar-d.mtvi.com/foo/bar?test=testString&test2=test2String

use-query-string is set to "true" in the urlrewrite element.

Question: How do you properly pass a query string?

Thanks for your consideration and any suggestions much appreciated!!


Ok, I figured this out. This was happening because I didn't close the "from" match with a "$" symbol. Here's how it should look:

<rule>
    <condition name="host">www.foo-d.com</condition>
    <from>^/foo/bal(\?)?(.*)?$</from>
    <to type="redirect" last="true">http://www.bar-d.mtvi.com/foo/bar?test=testString&amp;$2</to>
</rule>

The only issue here is that if there is no query string on the originating request, the "to" stmt still adds an ampersand at the end of the query string. To get past this you could create 2 rewrite rules, one that matches with a query string and the other with out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜