locked
outbound rules for custom tags with data-* attributes not working RRS feed

  • Question

  • User270131243 posted

    This is what i'm having trouble with.
    The outbound rules that work with regular attributes do not work with custom tags

    for example
    if i have <img src="/images/misc/something.jpg" data-src="/images/misc/somethingelse.jpg" />

    the outbound rule will rewrite this as

    <img src="http://mycdn.com/images/misc/something.jpg" data-src="/images/misc/somethingelse.jpg" />

    notice that the data-src attribute is not modified even tough my custom tag was supposed to take care of it with the <tag name="img" attribute="data-src" /> part

    Similarly

    Doesn't work
    <li data-bg-img="/Images/splash-screen/splash-home-2.jpg" class="splashli" style="background-color:#e79421;">
    Doesn't work
    <li class="splashli" style="background-color:#e79421;" imgsrc="/Images/splash-screen/splash-home-2.jpg" >


    Works!!!!!!!!
    <li imgsrc="/Images/splash-screen/splash-home-2.jpg" class="splashli" style="background-color:#e79421;">
    is rewritten as
    <li imgsrc="http://mycdn.com/Images/splash-screen/splash-home-2.jpg" class="splashli" style="background-color:#e79421;">

    What has changed? i moved the imgsrc attribute from being the last to being the first attribute of the <li> tag.
    However notice that this has no effect with attributes that have hyphens. i.e. "data-bg-img"

    judging from this post, i'm beginning to think there're some bugs with urlrewrite module and they still haven't been fixed since 2009. Any word on how to fix this? aside from ding filterbytag="none" which is a big performance hit. I've tried failed request tracing and i can't find anything wrong.

    here're the outbound rules.

    <outboundRules>
            <clear />
            <rule name="Out_Rewrite_cdn_http" preCondition="ResponseIsHtml" enabled="true" stopProcessing="true">
              <match filterByTags="A, Img, Link, Script, CustomTags" customTags="imgDataSrc" pattern="^/(Images(?!(/cart-item|/uploads))|Scripts|Styles)/(.*)$" />
              <action type="Rewrite" value="http://mycdn.com{R:0}" />
            </rule>
            <preConditions>
              <preCondition name="ResponseIsHtml">
                <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                <add input="{URL}" pattern="\.axd.*$" negate="true" />
                <add input="{URL}" pattern="\.ashx.*$" negate="true" />
              </preCondition>
            </preConditions>
            <customTags>
              <tags name="imgDataSrc">
                <tag name="img" attribute="data-src" />
                <tag name="li" attribute="data-bg-img" />
                <tag name="li" attribute="imgsrc" />
              </tags>
            </customTags>
    </outboundRules>

    Wednesday, August 13, 2014 2:20 AM

All replies

  • User1183424175 posted

    Hi,

    As a workaround, you can try changing your custom tag name as "datasrc" and "dataimg" without "-" characters. It should work for you.

    Please have a try.

    Wednesday, August 13, 2014 10:41 PM
  • User270131243 posted

    could do that yes, but it seems like a hack... and goes against the datasets of html5. also would have to modify alot of html then some javascripts that look for those attributes etc etc.

    Thursday, August 14, 2014 2:59 AM
  • User-292064232 posted

    I also want you to be able to use standard data attribute HTML5 in outboundRule. I believe that strange custom attributes should not be used.

    Thursday, October 30, 2014 6:35 AM
  • User1321518684 posted

    I also want you to be able to use standard data attribute HTML5 in outboundRule.

    Agree. I have the same problem. Can't rewrite URLs of data-src attributes within images. Please fix / add that feature.

    Tuesday, November 4, 2014 2:33 AM
  • User-486490069 posted

    I am having the same problem.  Really annoying, but not surprising that IIS can't handle something this easy.

    Wednesday, April 29, 2015 3:29 PM
  • User14123639 posted

    I had the same issue, and it appears that IIS cannot handle a custom tag that contains a hyphen

    A work around that worked for me was to use another outbound Rule. In this example I am attempting to replace the data-zoom-image attribute within an img tag.

    <rule name="RewriteRelativePathsCustomTags2" preCondition="IsHtml" enabled="true">
    	<match filterByTags="None" pattern="&lt;img ([^>]*)data-zoom-image=&quot;(.*?)&quot;([^>]*)>" />
    	<action type="Rewrite" value="&lt;img {R:1}data-zoom-image=&quot;YOUR VALUE HERE{R:2}&quot;{R:3}>" />
    </rule>				
    <preConditions>
    	<preCondition name="IsHtml">
    		<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
    	</preCondition>
    </preConditions>

    Hope this helps

    Tuesday, June 2, 2015 7:09 AM
  • User-292064232 posted

    This issue fixed by URL Rewrite Module 2015 May update.

    IMPORTANT - Changes in this release
    • Windows 10 Support - It is now possible to install URL Rewrite Module 2.0 on Windows 10 with this release
    • Custom attributes containing dashes are now supported. This is required as HTML 5 has the following rules for determining HTML attribute names: http://www.w3.org/TR/html-markup/syntax.html#syntax-attributes
    • Incorporates Hotfix for URL Rewrite 2.0 (June 2014) as in KB2974666

    http://www.microsoft.com/en-us/download/details.aspx?id=47337

    Sunday, June 7, 2015 12:21 PM
  • User270131243 posted

    I have the 05/27/2015 urlrewrite 2.0 installed now, but the issue doesn't seem to be fixed. it ignores attributes with "data-*", it does however work with "data*"

    Monday, June 29, 2015 8:47 PM
  • User14123639 posted

    Either install the hotfix mentioned in an earlier post or try a rule similar to this:

    <rule name="RewriteDataBgImg" preCondition="IsHtml" enabled="true">
    	<match filterByTags="None" pattern="&lt;li ([^>]*)data-bg-img=&quot;(.*?)&quot;([^>]*)>" />
    	<action type="Rewrite" value="&lt;li {R:1}data-bg-img=&quot;http://mycdn.com/{R:2}&quot;{R:3}>" />
    </rule>				
    <preConditions>
    	<preCondition name="IsHtml">
    		<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
    	</preCondition>
    </preConditions>

    Tuesday, June 30, 2015 4:36 AM