Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Is our .htaccess working for you?

Discussion in 'WebGL' started by jonas-echterhoff, Dec 16, 2015.

?

Does the .htaccess file written by Unity work for you to host compressed files over http?

  1. Yes.

    7 vote(s)
    19.4%
  2. It does not work but it does not cause harm either.

    10 vote(s)
    27.8%
  3. No, and I have to remove or change it to be able to host files.

    19 vote(s)
    52.8%
  1. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,635
    As you may know, Unity WebGL will write an invisible .htaccess file into the Release folder of builds in order to instruct the web server to host the build files using gzip compression on the http transfer level, allowing browsers to decompress the data while downloading.

    In 5.3, Unity will fall back to decompressing gzip in JavaScript if the server setup does not work, so you will always get compressed transfers, but you may have a few hundred ms of extra decompression time after the download if decompression is not handled by the protocol. Which means that having the server configured to handle compression is no longer a hard requirement for shipping anything, but is more like a minor optimization you can take.

    Now, I have seen plenty of threads now (and in the past) about the default .htaccess file we provide causing problems with many web servers and requiring changes. Now I'm wondering what to do here. Given that there are endless different web server configurations out there, it is very hard to come up with a configuration which will work everywhere. Given that 5.3 will give decent results using it's fallback JavaScript compression, I am wondering if we should just stop supplying a .htaccess file to avoid such issues - and when people want to benefit from http-level compression, they can set up such a file themselves.

    In order to make such a decision, I'd like to figure out how many people are having such problems. Is it a vocal minority on this forum, or most users, or somewhere in between? So, please comment on this thread and/or use the attached poll.
     
  2. Zaelot

    Zaelot

    Joined:
    Mar 26, 2015
    Posts:
    12
    Microsoft Azure (IIS) seems to ignore .htaccess files and needs custom web.config to work. Any chance you could generate that as well?
     
    ZiadJ likes this.
  3. BlueScreenISU

    BlueScreenISU

    Joined:
    Aug 27, 2015
    Posts:
    20
    Hello,

    before 5.3 I was able to host my files. I tried the compression way to do it, but failed, and sticked to uncompressed.
    Now in 5.3 I struggle to get anything running at all.
    The build output seems to be always compressed and I receive an internal server error:
    "Failed to load resource: the server responded with a status of 500 (Internal Server Error)"

    I really cant figure out why, I would love to make the compression approach work, but if not, I can not see how to use an umcompressed way in 5.3, can someone help me here?

    On topic I would say to remove the .htaccess and include all about compression in the documentation only? For me it made more trouble than anything else so far :(

    Blue
     
  4. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,635
    So, if you delete the .htaccess file on your server, will it work?

    This is what we will probably do.
     
  5. BlueScreenISU

    BlueScreenISU

    Joined:
    Aug 27, 2015
    Posts:
    20
    hello and thanks for your reply.

    I already tried deleting the .htaccess. Result:
    "UnityLoader.js:1 Invoking error handler due to
    Uncaught SyntaxError: Unexpected token <"

    "Uncaught SyntaxError: Unexpected token <
    blob:http%3A//www.i-show-you.de/de364561-e69d-4d7a-b910-47660802ae90:1"

    My guess is that the loader is running but fails to decompress the files? Cant find out what is exactly happening.

    Blue
     
  6. mm1000

    mm1000

    Joined:
    Dec 3, 2015
    Posts:
    3
    I'm using nodeJS + Express on the server side, so I don't need ".htaccess" files.
    However, for 5.2 builds I wrote some code to sent gzipped content to client.
     
  7. commodore

    commodore

    Joined:
    May 30, 2012
    Posts:
    36
    I'm getting the following error even after deleting the .htaccess file in the Release folder:

    "An error occured running the Unity content on this page. See your browser's JavaScript console for more info. The error was: uncaught exception: unknown compression method"

    My game seems to load up fine after I click Ok though.
     
  8. sushanta1991

    sushanta1991

    Joined:
    Apr 3, 2011
    Posts:
    288
    same here , it happens sometimes and with some users only, there is no fix pattern.
     
  9. commodore

    commodore

    Joined:
    May 30, 2012
    Posts:
    36
    Is the .htaccess file needed for Development builds? It is being added to the Development folder automatically. The file extensions are .data, .js and .mem so they shouldn't need to be decompressed, right?
     
  10. ikefrc

    ikefrc

    Joined:
    Jul 3, 2012
    Posts:
    81
  11. batate

    batate

    Joined:
    Mar 4, 2015
    Posts:
    31
    I have the default generated (5.3.1f1) Release/.htaccess file in place.. but to get this to work from our Unix Apache server I have to amend the index.html file generated to ADD gz on end of the three URLs... i.e. changing those to .datagz, .jsgz and .memgz

    If not I get the error others report. SyntaxError: expected expression, got '<'

    But with the modified index.html version it does not work when tested from a local file store. Using Firefox 43.0.1.

    My full report is at
    http://forum.unity3d.com/threads/we...ted-to-rewriting-of-gz-resource-files.375373/

    It seems that a RewriteBase needs to be added to the .htaccess file... and we moved it up to the index.html level, though I am no sure that is required.
     
    Last edited: Mar 29, 2016
  12. bigbadtrumpet125

    bigbadtrumpet125

    Joined:
    Apr 1, 2013
    Posts:
    18
    We host all of our files on amazon s3 and cloudfront, so as of now we are making the assumption that all of our users browsers who can run web gl will support gzip encoding. It appears that all major browsers have had this for the past 10 years-ish?

    So we don't actually use your .htacess concept or the fallback of adding "gz" to the end of the url. I would love to be able to do use that but since there isn't currently a (easy out of the box) way for us to sign the request for downloading in amazon (making the files public isn't ideal for us at this point) and because cloudfront doesnt support gzipping the .data and .mem files by default (it does for the javascript file, but it doesnt like binary files apparently)
     
  13. collenti

    collenti

    Joined:
    Feb 10, 2013
    Posts:
    3
    I hope this information is helpful.

    I was not able to get the webgl build running properly on my server. The server is Ubuntu (Linux Mint) Apache2. What did the trick was to make sure that (1) mod_delegate AND (2) mod_rewrite were up and running. After that, the gz files downloaded very fast, using the .htaccess out of the box from unity. The transferred to size ratio for the jsgz, datagz, and memgz files went down to .23 to 1.00 on average. The major problem had been from the /var/log/apache2/error.log was:

    .htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration

    So, if your admin doesn't have both mods up and running, then the whole project dies, unless you delete the .htaccess file altogether.

    dowload.png
     
  14. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    143
    We're getting errors as well when the htaccess file is removed - it works when everything is properly in place.. on our server.

    However, we haven't had any luck when deploying to multiple client servers. They are all setup differently and getting it to work has been more trouble than it was worth.

    I think some proper (tested) documentation on how to set it up and the removal of the file would be best. That said -> it must work properly without it.

    -Pieter
     
  15. Zaelot

    Zaelot

    Joined:
    Mar 26, 2015
    Posts:
    12
    One trick on a server that actually accepts .htaccess is to rename the packaged files in the Release folder to .gz (ie, just move the dot right by two spaces).
     
  16. Lloyd_RedironLabs

    Lloyd_RedironLabs

    Joined:
    May 17, 2013
    Posts:
    324
    We use IIS, so we have no need for the file anyway and its deleted by our build server. It would be nice if a standardized web.config was generated, otherwise, an option to not export this file would be good - it isn't usable by everyone...

    I've also had requests from my team to generate uncompressed files, which would be nice to be optional as well. If the file is going to be compressed for IIS, we'd much rather use dynamic compression and let the server compress it as required.

    My two cents - when wrapping a WebGL package in such a way it isn't a plain JS file (i.e. gzip) and knowing that it is intended to be used on different server configurations ... then I'd highly recommend documenting very clearly what the expectations are for different server configurations - and what the expected configuration files and options look like.

    Not trying to complain, but as it is, Unity in WebGL can be challenging. The many issues aside and focusing on builds for a moment ... We've been finding the build structure & build options change between Unity versions. It is common for the options, settings and build changes to have no documentation. And I've been finding that fixed WebGL issues are often missing in the release notes. This is compounded by the fact there is no easy way to determine OS and Browser inside of the Unity blob itself ... I've encountered plenty of WebPlayer and WebGL options that act very differently between platforms and browsers, it all comes together to make the process far more "trial and error" than it probably should be - and reinforces the dangerous problems that the WebPlayer has been shielding us from.
     
    Last edited: Feb 10, 2016
    Zaelot likes this.
  17. ReinaldoOrtiz

    ReinaldoOrtiz

    Joined:
    Jul 9, 2014
    Posts:
    3
    I had to add the mod_rewrite to Apache2 and also include the following two lines inside the .htaccess file:

    1. AddType application/octet-stream .memgz .datagz .unity3dgz
    2. AddType application/javascript .jsgz
    Running fine now on Ubuntu 14.04/Apache2.

    Hope it helps someone.
     
  18. GoeTeeks

    GoeTeeks

    Joined:
    Oct 15, 2015
    Posts:
    2
    I get this same error but my game won't load. Except on Internet Explorer (ironically). But it runs really slow on IE (not ironic at all). I tried Nightly, Firefox, Chrome, and Edge. I'm not sure if this is more of a server issue, browser issue, or OS/my laptop issue.
     
  19. ProfPivec

    ProfPivec

    Joined:
    Sep 21, 2012
    Posts:
    19
    I tried two difference Apache Servers and I also got the blank screen with WebGL - Unity 5.3, despite the Docs saying it will just work!

    However, I tried all of the above and nothing worked, but after wading through server error logs, the issue is with the htaccess file.

    If you delete it, the gzip compression doesn't happen and although everything works, the loading times are way longer. You do see the message in the javascript console that the Unity docs state.

    With the htaccess file that Unity provides in the Release folder, and with the mime types added, it still didn't work, even on an Apache Server.

    HOWEVER, one of the server logs showed....".htaccess: Option FollowSymLinks not allowed here"

    After some research, I replaced the +FollowSymLinks for +SymLinksIfOwnerMatch and everything works great even without the mime types added.

    Hence, if someone from Unity could please tell me where to change this in the editor, so I do not have to manually edit the file after each upload, that would be just great.

    I also tested firefox, chrome, safari, IE, and edge, all work great. Even Safari mobile worked (but very very slow).
    But as yet, I haven't figured out how to make Safari full screen. Any ideas?

    Hope this helps others, cost me the best part of the day running trial and error, but I am happy that I now have a WebGL solution that works on a server.
     
  20. Lloyd_RedironLabs

    Lloyd_RedironLabs

    Joined:
    May 17, 2013
    Posts:
    324
    Fwiw, they keep their template files in a subfolder in your Unity install. You can modify them so you aren't stuck with a relatively hollow template. Just be aware changes here will be wiped out every Unity update.
     
  21. Bungalow-12

    Bungalow-12

    Joined:
    Dec 10, 2013
    Posts:
    11
    I was able to convert the .htaccess file to a Web.config file for my azure page but I am getting the UnityLoader.js 500 issue mentioned above. Any idea how to make this work on Azure?
     
  22. sandeepsmartest

    sandeepsmartest

    Joined:
    Nov 7, 2012
    Posts:
    120
    Hi All,
    Below given is the error that pops out when I upload my webgl build to Apache server.
    Unity version 5.5.X
    Compression format: Gzip.
    How should i solve this issue. All threads and forums are saying to modify .htaccess file but unity is not generating .htaccess file!!
    Help is appreciated.
     
  23. Zaelot

    Zaelot

    Joined:
    Mar 26, 2015
    Posts:
    12
    Hi @sandeepsmartest ! Older versions of Unity were generating one, and they removed it due to different web servers using different kind of types of config files. Basically *nix based ones tend to use the .htaccess and Windows based ones web.config.
    Unity lets you donwload old versions, if you want to try generating such .htaccess config file. (Just start and build a new WebGL project. Sorry, I don't really remember when it was they dropped it off. Try something like 4.6..?)
    https://unity3d.com/get-unity/download/archive

    (And as you said, those usually need to be edited to suit your needs anyway, so I guess, try to find an open source example project to download an example or something?)
     
  24. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,250
    The docs explain it clearly.

    --Eric
     
    Zaelot likes this.
  25. sandeepsmartest

    sandeepsmartest

    Joined:
    Nov 7, 2012
    Posts:
    120
    Hi @Zaelot I made a build using Brotil compression format and is working fine.But i could see a longer waiting time to open.
     
  26. grimunk

    grimunk

    Joined:
    Oct 3, 2014
    Posts:
    260
    We are using S3/Cloudfront. AFAIK the .htaccess file is ignored so we don't include it.

    As far as we can tell, Unity is already compressing the files into webassets. We could turn the feature off, however S3's interface for enabling compression on things is... lackluster. It would be easier if the files that end in .webasset were just plain .js files and binary files. We long as the files are things S3 recognizes, it provides a compression option. It does not recognize .webasset, and so we can't turn off Unity compression and have S3 provide compression instead.
     
unityunity