# Enable URL rewriting
RewriteEngine On

# If the requested file/directory exists, serve it directly
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Redirect URLs with .php extension to clean URLs (without .php)
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

# Special pages mapping
RewriteRule ^kontakt/?$ /kontakt.php [L]
RewriteRule ^o-nama/?$ /o-nama.php [L]
RewriteRule ^svi-aparati/?$ /svi-aparati.php [L]
RewriteRule ^cart/?$ /cart.php [L]
RewriteRule ^checkout/?$ /checkout.php [L]
RewriteRule ^login/?$ /login.php [L]
RewriteRule ^register/?$ /register.php [L]
RewriteRule ^account/?$ /account.php [L]
RewriteRule ^aparati-za-varenje/?$ /aparati-za-varenje.php [L]

# For standard internal pages, map to .php version
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L]

# For all other requests, send to router.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /router.php?slug=$1 [L,QSA]