<IfModule mod_autoindex>
	Options -Indexes
</IfModule>

{if $config.mod_deflate}
# Gzip сжатие / поддерживается не на всех хостингах
<IfModule mod_deflate.c>
	# Compress HTML, CSS, JavaScript, Text, XML and fonts
	AddOutputFilterByType DEFLATE application/javascript
	AddOutputFilterByType DEFLATE application/rss+xml
	AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
	AddOutputFilterByType DEFLATE application/x-font
	AddOutputFilterByType DEFLATE application/x-font-opentype
	AddOutputFilterByType DEFLATE application/x-font-otf
	AddOutputFilterByType DEFLATE application/x-font-truetype
	AddOutputFilterByType DEFLATE application/x-font-ttf
	AddOutputFilterByType DEFLATE application/x-javascript
	AddOutputFilterByType DEFLATE application/xhtml+xml
	AddOutputFilterByType DEFLATE application/xml
	AddOutputFilterByType DEFLATE font/opentype
	AddOutputFilterByType DEFLATE font/otf
	AddOutputFilterByType DEFLATE font/ttf
	AddOutputFilterByType DEFLATE image/svg+xml
	AddOutputFilterByType DEFLATE image/x-icon
	AddOutputFilterByType DEFLATE text/css
	AddOutputFilterByType DEFLATE text/html
	AddOutputFilterByType DEFLATE text/javascript
	AddOutputFilterByType DEFLATE text/plain
	AddOutputFilterByType DEFLATE text/xml

	# Remove browser bugs (only needed for really old browsers)
	<ifmodule mod_setenvif.c>
		BrowserMatch ^Mozilla/4 gzip-only-text/html
		BrowserMatch ^Mozilla/4\.0[678] no-gzip
		BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
	</ifmodule>
</IfModule>
{/if}

{if $config.mod_headers}
<ifModule mod_headers.c>
	# Все html и htm файлы будут храниться в кэше браузера один день
	<FilesMatch "\.(html|htm)$">
		Header set Cache-Control "max-age=43200"
	</FilesMatch>
	# Все css, javascript и текстовые файлы будут храниться в кэше браузера одну неделю
	<FilesMatch "\.(js|css|txt)$">
		Header set Cache-Control "max-age=604800"
	</FilesMatch>
	# Все флэш файлы и изображения будут храниться в кэше браузера один месяц
	<FilesMatch "\.(flv|swf|ico|gif|jpg|jpeg|png)$">
		Header set Cache-Control "max-age=43200"
	</FilesMatch>
	# Отключаем кеширование php и других служебных файлов
	<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
	Header unset Cache-Control
	</FilesMatch>
</IfModule>
{/if}

{if $config.mod_expires}
# Кэширование / поддерживается не на всех хостингах
<ifmodule mod_expires.c>
	<filesmatch "\.(jpg|jpeg|png|gif|js|css|swf|ico|woff|mp3)$">
	ExpiresActive on
	ExpiresDefault "access plus 7 days"
	</filesmatch>
</ifmodule>
{/if}

# Google PageSpeed Insights модуль PageSpeed,есть не на всех хостингах и не везде может работать, нужно уточнять у хостеров
<IfModule pagespeed_module>
	ModPagespeed on
	ModPagespeedRewriteLevel CoreFilters
	ModPagespeedEnableFilters make_google_analytics_async
	ModPagespeedEnableFilters prioritize_critical_css
	ModPagespeedEnableFilters defer_javascript
	ModPagespeedEnableFilters sprite_images
	ModPagespeedEnableFilters convert_png_to_jpeg,convert_jpeg_to_webp
	ModPagespeedEnableFilters collapse_whitespace,remove_comments
</IfModule>

{if $homePageId}
DirectoryIndex /public/section.php?sectionId={$homePageId}&rewrite={$rewrite}
{/if}
RewriteEngine On


SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1


{if IS_HTTPS}{literal}
RewriteCond %{HTTPS} =off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]
{/literal}{/if}
ErrorDocument 404 /public/error-404.php?rewrite={$rewrite}

{if $config.compress_js_css}
RewriteCond %{ldelim}REQUEST_FILENAME{rdelim} -f
RewriteRule ^(.+\.(css|js))$ /compress.php?path=$1&rewrite={$rewrite} [L]
{/if}

RewriteRule ^rss.xml$ /public/rss.php?rewrite={$rewrite} [L]
RewriteRule ^sitemap.xml$ /public/sitemap.php?rewrite={$rewrite} [L]

{foreach item=section from=$SECTIONS}{if $section.type eq "plain"}
{if $section.fileName eq "index"}
RewriteRule ^{preg_quote($section.dir)}\.{$config.file_extension}$ {$SITE_URL}/ [L,R=301]
{else}
RewriteRule ^{preg_quote($section.dir)}\.{$config.file_extension}$ /public/section.php?sectionId={$section.sectionId}&rewrite={$rewrite} [L]
{/if}

{/if}{/foreach}

#RewriteRule ^brands/([^/]+)/page([0-9]+)\.{$config.file_extension}$ /public/brand.php?{literal}%{QUERY_STRING}{/literal}&fileName=$1&page=$2&rewrite={$rewrite} [L]
RewriteRule ^brands/([^/]+)/([^/]+)/page([0-9]+)\.{$config.file_extension}$ /public/brand.php?{literal}%{QUERY_STRING}{/literal}&fileName=$1&page=$2&rewrite={$rewrite} [L]
RewriteRule ^brands/([^/]+)/([^/]+) /public/brand.php?{literal}%{QUERY_STRING}{/literal}&fileName=$1&param=$2&rewrite={$rewrite} [L]
RewriteRule ^brands/([^/]+) /public/brand.php?{literal}%{QUERY_STRING}{/literal}&fileName=$1&rewrite={$rewrite} [L]

{foreach item=section from=$SECTIONS}{if $section.type eq "tree"}
{if $section.typeContent eq "products"}

RewriteRule ^{preg_quote($section.dir)}$ {$section.path}/ [L,R=301]
RewriteRule ^{preg_quote($section.dir)}/$ /public/section.php?{literal}%{QUERY_STRING}{/literal}&sectionId={$section.sectionId}&rewrite={$rewrite} [L]
RewriteRule ^{preg_quote($section.dir)}/page([0-9]+)\.{$config.file_extension}$ /public/section.php?{literal}%{QUERY_STRING}{/literal}&sectionId={$section.sectionId}&page=$1&rewrite={$rewrite} [L]
RewriteRule ^{preg_quote($section.dir)}/([^/]+)\.{$config.file_extension}$ /public/product.php?{literal}%{QUERY_STRING}{/literal}&fileName=$1&sectionId={$section.sectionId}&rewrite={$rewrite} [L]

{else}

RewriteRule ^{preg_quote($section.dir)}$ {$section.path}/ [L,R=301]
RewriteRule ^{preg_quote($section.dir)}/$ /public/section.php?{literal}%{QUERY_STRING}{/literal}&sectionId={$section.sectionId}&rewrite={$rewrite} [L]
RewriteRule ^{preg_quote($section.dir)}/page([0-9]+)\.{$config.file_extension}$ /public/section.php?{literal}%{QUERY_STRING}{/literal}&sectionId={$section.sectionId}&page=$1&rewrite={$rewrite} [L]
RewriteRule ^{preg_quote($section.dir)}/([^/]+)\.{$config.file_extension}$ /public/article.php?{literal}%{QUERY_STRING}{/literal}&fileName=$1&sectionId={$section.sectionId}&rewrite={$rewrite} [L]
{/if}

{/if}{/foreach}

# все запросы в префиксом (ajax) будут обрабатываться следующим образом ajax-(что здесь будет) /public/ajax-feedback СЮДА ПРИДЕТ.php
RewriteRule ^ajax-(.*) /public/ajax-$1.php?rewrite={$rewrite} [QSA]
# все запросы в префиксом (api) будут обрабатываться следующим образом api-(что здесь будет) /public/api-app СЮДА ПРИДЕТ.php
RewriteRule ^api-(.*) /public/api-$1.php?rewrite={$rewrite} [QSA]

# Set the “ea-php74” package as the default “PHP” programming language.
#<IfModule mime_module>
#	AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
#</IfModule>

