Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rhys Baillie 2 posts 72 karma points
    Jul 12, 2017 @ 20:24
    Rhys Baillie
    0

    Remove .html from Url using web.config produces errors

    Hi All, I've got a rewrite rule in web.config which is rewriting the URL to remove .html from all requests which is great, works like a charm.

    However it produces an error when looking in the CMS at any page which contains a Macro, where the Macro is unable to find the "GetMacroResultAsHtmlForEditor".

    I'm not convinces at publishing a page which produces errors for obvious reasons (it's a live site). I'm convinces that the rewrite rule is doing something to the Backend which is not great! The error is:

    Request error: The URL returned a 404 (not found): /umbraco/backoffice/UmbracoApi/Macro/GetMacroResultAsHtmlForEditor with data: {"macroAlias":"ImageSlider","pageId":"1258","macroParams":{}} Contact your administrator for information.

    and the rewrite rule is:

      <rules>
        <rule name="Hide .html ext">
          <match ignoreCase="true" url="^(.*)"/>
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
            <add input="{REQUEST_FILENAME}.html" matchType="IsFile"/>
          </conditions>
          <action type="Rewrite" url="{R:0}.html"/>
        </rule>
        <rule name="Redirecting .html ext" stopProcessing="true">
          <match url="^(.*).html"/>
          <conditions logicalGrouping="MatchAny">
            <add input="{URL}" pattern="(.*).html"/>
          </conditions>
          <action type="Redirect" url="{R:1}"/>
        </rule>
      </rules>
    

    can anyone advise / help with this please? Umbraco version 7.4.3 assembly: 1.0.5948.18141 and using EUKHosts Plesk Hosting

    Many thanks

    Rhys

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Jul 13, 2017 @ 12:48
    Marc Goodson
    0

    I'm not sure this is the answer, but one thing I noticed in your regex, is that the . before the html isn't escaped...

    and . in regex parlance means match anything and so maybe your:

    (.*).html
    

    isn't matching everything before the .html

    but just being greedy and matching everything with html in

    can't see how it's necessarily related to the issue you are seeing but thought maybe

    (.*)\.html
    

    might be closer to what you were trying to achieve, so apologies if it's a digression to the main question but thought I'd mention it anyway, not that I can ever remember what regex syntax should properly be!

  • Rhys Baillie 2 posts 72 karma points
    Jul 13, 2017 @ 21:58
    Rhys Baillie
    0

    Hi marc goodson, thanks for that, it did correct the GetHtml.. error so big thanks for that! However, something else that I've noticed is that when adding an element to the grid, something that requires a setting input (such as a macro) the slide-in config page is blank. I suspect this rewrite is doing more harm than good and I should look for an alternative. Many thanks though, getting there!

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Jul 14, 2017 @ 08:07
    Marc Goodson
    0

    Hi Rhys

    ahh, it's just to rewrite an old version of your site on the front end now you've moved to Umbraco and you want to make sure old links to the .html versions still work / redirect correctly.

    In which case you may have some joy by excluding the rewriting from applying to any request within the Umbraco folder - so it doesn't clash with the innerworkings, that will use .html files as views for some of the backoffice bits:

    eg add to your conditions:

      <add input="{URL}" pattern="/Umbraco/*" negate="true" />
    

    see if that helps.

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft