# license-php/.htaccess
# Clean URL Routing for cPanel / Apache

RewriteEngine On

# Block direct access to data directory
RewriteRule ^data/ - [F,L]


# Allow direct file access if file exists
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Route Public License API Endpoints
RewriteRule ^api/license/public-key/?$ api/public-key.php [L,QSA]
RewriteRule ^api/license/status/?$ api/status.php [L,QSA]
RewriteRule ^api/license/activate/?$ api/activate.php [L,QSA]
RewriteRule ^api/license/verify/?$ api/verify.php [L,QSA]
RewriteRule ^api/license/deactivate/?$ api/deactivate.php [L,QSA]

# Route Admin API Endpoints
RewriteRule ^api/admin/licenses/generate/?$ admin/api.php?action=generate [L,QSA]
RewriteRule ^api/admin/licenses/suspend/?$ admin/api.php?action=suspend [L,QSA]
RewriteRule ^api/admin/licenses/revoke/?$ admin/api.php?action=revoke [L,QSA]
RewriteRule ^api/admin/licenses/reactivate/?$ admin/api.php?action=reactivate [L,QSA]
RewriteRule ^api/admin/licenses/reset-domain/?$ admin/api.php?action=reset-domain [L,QSA]
RewriteRule ^api/admin/licenses/extend/?$ admin/api.php?action=extend [L,QSA]
RewriteRule ^api/admin/licenses/?$ admin/api.php?action=list [L,QSA]
RewriteRule ^api/admin/stats/?$ admin/api.php?action=stats [L,QSA]
RewriteRule ^api/admin/audit-logs/?$ admin/api.php?action=logs [L,QSA]
RewriteRule ^api/admin/license-logs/?$ admin/api.php?action=logs [L,QSA]

# Protect sensitive directories
<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>

<FilesMatch "(config\.php|schema\.sql|\.sqlite|\.pem|\.key)$">
    Order allow,deny
    Deny from all
</FilesMatch>
