{% if glpi_alias is defined %}
Alias /{{ glpi_alias }} {{ glpi_root_dir }}/web/public
{% else %}
# No alias defined, create a vhost to access it
{% endif %}

<Directory {{ glpi_root_dir }}/web/public>
  AllowOverride All
  Options FollowSymLinks
{% if glpi_src_ip is defined %}
  Require ip {{ glpi_src_ip | join(' ') }}
{% else %}
  Require all granted
{% endif %}

  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [L,QSA]

  <FilesMatch \.php$>
    # For some (unknown) reason, files at the root like apirest.php won't be handled by the rewrite rule
    # So force SCRIPT_NAME here (except for sso.php which is in the public subdir)
    ProxyFCGISetEnvIf "reqenv('Request_URI') !~ m/sso\.php$/" SCRIPT_FILENAME "{{ glpi_root_dir }}/web/public/index.php"
    SetHandler "proxy:unix:/run/php-fpm/{{ glpi_php_fpm_pool | default('glpi_' + glpi_id | string) }}.sock|fcgi://localhost"
  </FilesMatch>

</Directory>
