Search Unity

Why was .htaccess removed in 5.4?

Discussion in 'Web' started by zee_ola05, Aug 6, 2016.

  1. zee_ola05

    zee_ola05

    Joined:
    Feb 2, 2014
    Posts:
    166
    Why was .htaccess removed in 5.4? What is the reasoning behind this?
     
  2. alexsuvorov

    alexsuvorov

    Unity Technologies

    Joined:
    Nov 15, 2015
    Posts:
    327
    Hello zee_ola05.

    There are the following reasons for this:

    a) The original .htaccess in some special cases caused conflicts with the server configuration (i.e. forbidden FollowSymLinks or missing modules) so the files could not be served at all, while the advantage of using .htaccess is not that much significant (you can normally win less than a second for the loading time if you configure your server properly).

    b) .htaccess only applies to Apache servers, while many people are also using IIS, so it would be reasonable to include web.config in the build as well then. Unfortunately, there does not seem to be a universal configuration file for IIS, as it would depend on whether URL Rewrite module has been installed or not.

    It has therefore been decided to add a server configuration guide to the documentation (coming soon) instead of including server configuration files in the build, as every server has its own features and limitations, so the developer can adjust the server configuration appropriately.

    You may use the following configuration files for your Release subfoder:

    1) Release/.htaccess for Apache:
    Code (config):
    1. Options +SymLinksIfOwnerMatch
    2. <IfModule mod_rewrite.c>
    3.   <IfModule mod_mime.c>
    4.  
    5.     RewriteEngine on
    6.     RewriteCond %{HTTP:Accept-encoding} gzip
    7.     RewriteCond %{REQUEST_FILENAME}gz -f
    8.     RewriteRule ^(.*)\.(js|data|mem|unity3d)$ $1.$2gz [L]
    9.    
    10.     AddEncoding gzip .jsgz
    11.     AddEncoding gzip .datagz
    12.     AddEncoding gzip .memgz
    13.     AddEncoding gzip .unity3dgz
    14.  
    15.   </IfModule>
    16. </IfModule>


    2) Release/web.config for IIS without URL Rewrite module installed (you need at least the following configuration to run your build from IIS server, as by default IIS does not serve files which do not have associated MIME type for its extensions, also note that you only need <remove fileExtension=".*" /> block if you expect MIME types to be overridden at the higher levels, in which case you might otherwise end up with error 500):
    Code (config):
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <configuration>
    3.     <system.webServer>
    4.         <staticContent>
    5.             <remove fileExtension=".mem" />
    6.             <remove fileExtension=".data" />
    7.             <remove fileExtension=".unity3d" />
    8.             <remove fileExtension=".jsgz" />
    9.             <remove fileExtension=".memgz" />
    10.             <remove fileExtension=".datagz" />
    11.             <remove fileExtension=".unity3dgz" />
    12.             <mimeMap fileExtension=".mem" mimeType="application/octet-stream" />
    13.             <mimeMap fileExtension=".data" mimeType="application/octet-stream" />
    14.             <mimeMap fileExtension=".unity3d" mimeType="application/octet-stream" />
    15.             <mimeMap fileExtension=".jsgz" mimeType="application/octet-stream" />
    16.             <mimeMap fileExtension=".memgz" mimeType="application/octet-stream" />
    17.             <mimeMap fileExtension=".datagz" mimeType="application/octet-stream" />
    18.             <mimeMap fileExtension=".unity3dgz" mimeType="application/octet-stream" />
    19.         </staticContent>
    20.     </system.webServer>
    21. </configuration>


    3) Release/web.config for IIS with URL Rewrite module (http://www.iis.net/downloads/microsoft/url-rewrite) installed (as mentioned before, you only need <remove fileExtension=".*" /> block if you expect MIME types to be overridden at the higher levels):
    Code (config):
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <configuration>
    3.     <system.webServer>
    4.         <staticContent>
    5.             <remove fileExtension=".mem" />
    6.             <remove fileExtension=".data" />
    7.             <remove fileExtension=".unity3d" />
    8.             <remove fileExtension=".jsgz" />
    9.             <remove fileExtension=".memgz" />
    10.             <remove fileExtension=".datagz" />
    11.             <remove fileExtension=".unity3dgz" />
    12.             <mimeMap fileExtension=".mem" mimeType="application/octet-stream" />
    13.             <mimeMap fileExtension=".data" mimeType="application/octet-stream" />
    14.             <mimeMap fileExtension=".unity3d" mimeType="application/octet-stream" />
    15.             <mimeMap fileExtension=".jsgz" mimeType="application/octet-stream" />
    16.             <mimeMap fileExtension=".memgz" mimeType="application/octet-stream" />
    17.             <mimeMap fileExtension=".datagz" mimeType="application/octet-stream" />
    18.             <mimeMap fileExtension=".unity3dgz" mimeType="application/octet-stream" />
    19.         </staticContent>
    20.         <rewrite>
    21.             <rules>
    22.                 <rule name="Append gz suffix to WebGL content requests">
    23.                     <match url="(.*)\.(js|data|mem|unity3d)$" />
    24.                     <conditions>
    25.                         <add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" />
    26.                         <add input="{REQUEST_FILENAME}gz" matchType="IsFile" />
    27.                     </conditions>
    28.                     <action type="Rewrite" url="{R:1}.{R:2}gz" />
    29.                 </rule>
    30.             </rules>
    31.             <outboundRules>
    32.                 <rule name="Append gzip Content-Encoding header to the rewritten responses">
    33.                     <match serverVariable="RESPONSE_Content-Encoding" pattern=".*" />
    34.                     <conditions>
    35.                         <add input="{REQUEST_FILENAME}" pattern="\.(js|data|mem|unity3d)gz$" />
    36.                     </conditions>
    37.                     <action type="Rewrite" value="gzip" />
    38.                 </rule>
    39.             </outboundRules>
    40.         </rewrite>
    41.     </system.webServer>
    42. </configuration>
     
    Salazar, Evgeny-Eliseev and Aurigan like this.
  3. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    If the docs are going to be updated, i think it could be helpful to add the steps needed to host the game on popular cloud services (e.g: Amazon S3, for example).

    There are frequent questions here in the forums on how to host a WebGL game on platform X. If you include such information it could probably help out.
     
    zee_ola05 and pera2 like this.
  4. Nolex

    Nolex

    Joined:
    Dec 10, 2010
    Posts:
    116
    I have no acceess to configuration of URL Rewrite module.
    The loader is work incorrectly (0.0 and 1.0 values only). What to do?

    Unity 5.4.5.
     
  5. keraj37

    keraj37

    Joined:
    Nov 25, 2011
    Posts:
    28
    Maybe ask admin to grant you access. Easiest way :)
     
  6. Nolex

    Nolex

    Joined:
    Dec 10, 2010
    Posts:
    116
    @keraj37,
    Yes... But in my cdn it's not necesary. :)