orodsem/trout/trout/web/.htaccess - Htaccess File


# See HTML5 Boilerplate for an explaination of these directives.
# https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess

# Default charset UTF-8
AddDefaultCharset utf-8

# Prevent apache giving a 404 for a rewrite
Options -MultiViews

# Force UTF-8 for certain file formats.
<IfModule mod_mime.c>
    AddCharset utf-8 .atom .css .js .json .jsonld .rss .vtt .webapp .xml

# Prevent browsing of directory contents
<IfModule mod_autoindex.c>
    Options -Indexes

# Force IE to render in the highest compatible render mode
<IfModule mod_headers.c>
    Header set X-UA-Compatible "IE=edge"
    # `mod_headers` cannot match based on the content-type, however, this
    # header should be send only for HTML pages and not for the other resources
    <FilesMatch ".(appcache|atom|crx|css|cur|eot|f4[abpv]|flv|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|tt[cf]|vcf|vtt|webapp|web[mp]|woff|xml|xpi)$">
    Header unset X-UA-Compatible

# Additional MIME types and normalisation
<IfModule mod_mime.c>
    AddType application/json                            json
    AddType application/javascript                      js
    AddType application/font-woff                       woff
    AddType application/vnd.ms-fontobject               eot
    AddType application/x-font-ttf                      ttc ttf
    AddType font/opentype                               otf
    AddType     image/svg+xml                           svgz
    AddEncoding gzip                                    svgz
    AddType application/xml                             atom rdf rss xml

# Prevent browsers from mime-sniffing.
# Can prevent mallicious users distributing attack vecotrs in uploaded files
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"

# File compression
<IfModule mod_deflate.c>

    # Force compression for mangled headers.
    <IfModule mod_setenvif.c>
        <IfModule mod_headers.c>
            SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)s*,?s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
            RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding

    # Compress all output labeled with one of the following MIME-types
    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE application/atom+xml 

# Set expiry times for static assets to co-inside with Varnish configuration
<IfModule mod_expires.c>
    ExpiresActive on

    # Ever-changing; HTML, JSON
    ExpiresByType text/html                             "access plus 0 seconds"
    ExpiresByType application/json                      "access plus 0 seconds"

    # User modifyabele (images)
    ExpiresByType image/gif                             "access plus 1 hour"
    ExpiresByType image/png                             "access plus 1 hour"
    ExpiresByType image/jpeg                            "access plus 1 hour"

    # Semi-static; CSS, JS, Images
    ExpiresByType text/css                              "access plus 1 week"
    ExpiresByType application/javascript                "access plus 1 week"

    # Very-static; fonts, HTC files, icons
    ExpiresByType image/x-icon                          "access plus 1 month"
    ExpiresByType text/x-component                      "access plus 1 month"
    ExpiresByType application/font-woff                 "access plus 1 month"
    ExpiresByType application/vnd.ms-fontobject         "access plus 1 month"
    ExpiresByType application/x-font-ttf                "access plus 1 month"
    ExpiresByType font/opentype                         "access plus 1 month"
    ExpiresByType image/svg+xml                         "access plus 1 month"

# Use the front controller as index file. It serves as fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# startpage (path "/") because otherwise Apache will apply the rewritting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app_dev.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Determine the RewriteBase automatically and set it as environment variable.
    # If you are using Apache aliases to do mass virtual hosting or installed the
    # project in a subdirectory, the base path will be prepended to allow proper
    # resolution of the app.php file and to redirect to the correct URI. It will
    # work in environments without path prefix as well, providing a safe, one-size
    # fits all solution. But as you do not need it in this case, you can comment
    # the following 2 lines to eliminate the overhead.
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::2$
    RewriteRule ^(.*) - [E=BASE:%1]

    # Redirect to URI without front controller to prevent duplicate content
    # (with and without `/app.php`). Only do this redirect on the initial
    # rewrite by Apache and not on subsequent cycles. Otherwise we would get an
    # endless redirect loop (request -> rewrite to front controller ->
    # redirect -> request -> ...).
    # So in case you get a "too many redirects" error or you always get redirected
    # to the startpage because your Apache does not expose the REDIRECT_STATUS
    # environment variable, you have 2 choices:
    # - disable this feature by commenting the following 2 lines or
    # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
    #   following RewriteCond (best solution)
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    # If the requested filename exists, simply serve it.
    # We only want to let Apache serve files and not directories.
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    # Rewrite all other queries to the front controller.
    RewriteRule .? %{ENV:BASE}/app_dev.php [L]

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        # When mod_rewrite is not available, we instruct a temporary redirect of
        # the startpage to the front controller explicitly so that the website
        # and the generated links can still be used.
        RedirectMatch 302 ^/$ /app_dev.php/
        # RedirectTemp cannot be used instead

On Github License


Download PDF of Htaccess file