RewriteEngine On

RewriteBase /php-project-starter/

<IfModule mod_brotli.c>
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css text/javascript application/javascript application/json application/xml text/xml image/svg+xml font/ttf font/otf application/vnd.ms-fontobject
</IfModule>
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json application/xml text/xml image/svg+xml font/ttf font/otf application/vnd.ms-fontobject
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg      "access plus 1 month"
    ExpiresByType image/png       "access plus 1 month"
    ExpiresByType image/gif       "access plus 1 month"
    ExpiresByType image/webp      "access plus 1 month"
    ExpiresByType image/svg+xml   "access plus 1 month"
    ExpiresByType image/x-icon    "access plus 1 month"
    ExpiresByType text/css        "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType text/javascript "access plus 1 week"
    ExpiresByType font/ttf        "access plus 1 month"
    ExpiresByType font/otf        "access plus 1 month"
    ExpiresByType font/woff       "access plus 1 month"
    ExpiresByType font/woff2      "access plus 1 month"
</IfModule>
<IfModule mod_headers.c>
    <FilesMatch "\.(jpg|jpeg|png|gif|webp|svg|ico|css|js|ttf|otf|woff|woff2|eot)$">
        Header set Cache-Control "public, max-age=604800"
    </FilesMatch>
</IfModule>

RewriteCond %{REQUEST_URI} admin/ [NC]
RewriteCond %{REQUEST_URI} \.php$ [NC]
RewriteRule ^ - [F,L]

RewriteRule (^|/)admin/?$ - [F,L]

RewriteRule (^|/)\.(?!well-known/) - [F,L]
RewriteRule \.(md|sql|bak|old|orig|swp|log|ini|bat|cmd|sh|ps1|lock|dist|example|zip|tar|gz|tgz|7z|rar|env|yml|yaml|phar)$ - [F,L,NC]
RewriteRule ^(composer\.(json|lock)|package(-lock)?\.json|VERSION|PLUGIN_BUILDER_PROMPT\.txt|CLAUDE\.md.*|_login_resp\.html|installed\.lock)$ - [F,L,NC]
RewriteRule ^(database|vendor|backups|cache)(/|$) - [F,L,NC]
RewriteRule ^(db|theme-loader|theme-registry|render-builder-tree|page-sections-render)\.php$ - [F,L,NC]
RewriteRule ^themes/.+\.(php|phtml|inc)$ - [F,L,NC]
RewriteRule ^uploads/.+\.(php\d?|phtml|pht|phar|cgi|pl|py|asp|aspx|jsp|sh|exe|html?|js)$ - [F,L,NC]

Options -Indexes

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^sitemap\.xml$ sitemap.php [L]

RewriteCond %{REQUEST_METHOD} GET
RewriteRule ^([a-zA-Z0-9_-]+)\.php$ $1 [R=301,L]

RewriteRule ^([a-zA-Z0-9_-]+)\.php$ router.php?page=$1.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)$ router.php?page=$1.php [L,QSA]

RewriteRule ^([a-zA-Z0-9_-]+)/?(.*)$ gate.php?token=$1&path=$2 [L,QSA]
