Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WebGL build served from Apache gives error related to rewriting of gz resource files

Discussion in 'Web' started by batate, Dec 21, 2015.

  1. batate

    batate

    Joined:
    Mar 4, 2015
    Posts:
    31
    I wonder if anyone can help with an issue on a Unity WebGL deployment via Apache web server ***

    I perform the WebGL build and it creates the usual index.html file, and the Release and TemplateData folders, and the defaulty created Release/.htaccess rewrite rules are in there. The Release directory contains *.gz versions of the three resource files and UnityLoader.js

    Release/App-Name.datagz
    Release/App-Name.jsgz
    Release/App-name.memg

    and the index.html files has in it URLs without the gz ending.

    dataUrl: "Release/App-Name.data",
    codeUrl: "Release/App-Name.js",
    memUrl: "Release/App-name.mem",

    This version runs fine when I run it locally directly off my Windows PC (not over a web server) and I assume the gz versions of the resources files are designed to be expanded on need.

    HOWEVER, when I deploy this version of the WebGL built to our Apache server and try to run that served from there I get an error...

    An error occured running the Unity content on this page. See your browser's JavaScript console for more info. The error was: SyntaxError: expected expression, got '<'

    BUT, if I edit the index.html file to directly mention gz vesrions of the resource files it works when served from the Apache server.

    dataUrl: "Release/App-Name.datagz",
    codeUrl: "Release/App-Name.jsgz",
    memUrl: "Release/App-name.memgz",

    This modified version though does NOT work when run from local filestore.

    Has anyone seen this issue, is more needed in the default Resource/.htaccess file or is something else in the configuration of our Apache server at fault?

    *** Unity3D shows this for all recent versions, but using 5.3.1f1 at present.
    *** Apache 2.2.15 is on a university Unix server and is usually well configured.
    *** Using Firefox 43.0.1 as the web browser.
     
    Last edited: Dec 21, 2015
    Mikael-H likes this.
  2. batate

    batate

    Joined:
    Mar 4, 2015
    Posts:
    31
    I have advice from our systems team... who fixed this as follows.... this may be useful to Unity devs in designing the default index.html and .htaccess files perhaps?

    The problem is/was the lack of a suitable RewriteBase in the .htaccess file.


    It was correctly determining whether to send the compressed file, but it was wrongly working out where that compressed file was. This is due to a short coming with using rewrite rules in .htaccess files. You have to help it along by specifying the URL container that the .htaccess is in.



    I've moved the .htaccess out of Release up one level to the same level as index.html and then added a RewriteBase line so that the rewrites are now working as expected
     
    Mikael-H likes this.