We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 2035
    • 19 Posts
    Hello! I have a problem. It needs different "Content-Type" for IE and for Others Browsers.
    So I want to send to NON-IE-browsers ’Content-Type: application/xhtml+xml’ and to IE ’Content-Type: text/html’.
    (IE could not properly process ’Content-Type: application/xhtml+xml’).
    So it’s very simple decision, if no CMS used:
    <?php 
       if(preg_match('|application/xhtml\+xml|i',$_SERVER['HTTP_ACCEPT']))
          header('Content-Type: application/xhtml+xml');
       else
          header('Content-Type: text/html');
    ?>


    but i’m not really know how to integrate this decision into MODx Revolution 2.0.8. May be i should wrote a plugin, which should executes on ’OnWebPagePrerender’ event?
    Is anybody could help me with code? smiley
      • 22303 MODX Staff
      • 10,725 Posts
      A plugin OnWebPagePrerender should work with that code, though I would add something limiting execution of the preg_match() to when the current Resource’s ContentType matches, e.g.
      <?php
      if ($modx->resource->ContentType->get('mime_type') == 'application/xhtml+xml') {
          if (preg_match('|application/xhtml\+xml|i', $_SERVER['HTTP_ACCEPT'])) {
              header('Content-Type: application/xhtml+xml');
          } else {
              header('Content-Type: text/html');
          }
      }
        • 2035
        • 19 Posts
        YEAH! Amazing! Big thanks, OpenGeek!! So the final decision is:
        1) At CMS i’m used for every Resource default ContentType: "text/html"
        2) Wrote plugin, which firing ’OnWebPagePrerender’;
        3) The plugin’s code is:
        <?php
          if (preg_match('|application/xhtml\+xml|i', $_SERVER['HTTP_ACCEPT']))
            $modx->resource->ContentType->set('mime_type','application/xhtml+xml');
        

        So, if the browser do not supports ContentType ’application/xhtml+xml’ (e.g. IE 5.5 - IE 8.0), header ’Content-Type’, would not be modified (so ’Content-Type: text/html’ will be send).
        Otherwise header would be modified to ’Content-Type: application/xhtml+xml’.

        It’s was necessary for me to using inline-svg. laugh