# SplendApp — Apache rules (PHP 8.4, no framework)
Options -Indexes -MultiViews
DirectoryIndex index.php
AddDefaultCharset UTF-8

<IfModule mod_headers.c>
  Header always set X-Content-Type-Options "nosniff"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# Block hidden files and private folders
<FilesMatch "^\.">
  Require all denied
</FilesMatch>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# https + no www
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]

# private folders
RewriteRule ^(includes|storage|lang|cron)(/|$) - [F,L]

# old WordPress system addresses
RewriteRule ^(wp-admin|wp-login\.php|xmlrpc\.php|wp-json)(/.*)?$ - [R=404,L]

# add the trailing slash WordPress used (pages only, not files)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{2,5}$
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_METHOD} GET
RewriteRule ^(.*)$ /$1/ [L,R=301]

# sitemap + feed
RewriteRule ^sitemap_index\.xml$ sitemap.php [L,QSA]
RewriteRule ^sitemap\.xml$ sitemap.php [L,QSA]
RewriteRule ^([a-z]+)-sitemap([0-9]*)\.xml$ sitemap.php?type=$1&n=$2 [L,QSA]
RewriteRule ^(en/)?feed/?$ feed.php?lang=$1 [L,QSA,B]

# real files and folders are served as they are
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# English home
RewriteRule ^en/?$ index.php?lang=en [L,QSA]

# categories / tags (with paging)
RewriteRule ^(en/)?category/(.+?)/page/([0-9]+)/?$ category.php?lang=$1&slug=$2&pg=$3 [L,QSA,B]
RewriteRule ^(en/)?category/(.+?)/?$ category.php?lang=$1&slug=$2 [L,QSA,B]
RewriteRule ^(en/)?tag/(.+?)/page/([0-9]+)/?$ tag.php?lang=$1&slug=$2&pg=$3 [L,QSA,B]
RewriteRule ^(en/)?tag/(.+?)/?$ tag.php?lang=$1&slug=$2 [L,QSA,B]
RewriteRule ^(en/)?page/([0-9]+)/?$ search.php?lang=$1&pg=$2 [L,QSA,B]

# pages, posts and feature pages
RewriteRule ^en/(.+?)/?$ view.php?lang=en&path=$1 [L,QSA,B]
RewriteRule ^(.+?)/?$ view.php?path=$1 [L,QSA,B]
</IfModule>

ErrorDocument 404 /404.php

# Browser caching for static files
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType image/webp "access plus 6 months"
  ExpiresByType image/png "access plus 6 months"
  ExpiresByType image/jpeg "access plus 6 months"
  ExpiresByType image/svg+xml "access plus 6 months"
  ExpiresByType font/woff2 "access plus 1 year"
</IfModule>
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json image/svg+xml application/xml
</IfModule>
