# bnuuy Atelier storefront clean URLs
# Applies only inside /shop/

Options -MultiViews
DirectoryIndex index.php

RewriteEngine On

# /shop/index.php -> /shop/
# GET/HEAD only so form POST data is never redirected away.
RewriteCond %{REQUEST_METHOD} ^(?:GET|HEAD)$
RewriteCond %{THE_REQUEST} \s/+(.*/)?index\.php(?:[?\s]) [NC]
RewriteRule ^index\.php$ ./ [R=302,L,NE]

# /shop/cart.php -> /shop/cart
# /shop/checkout.php -> /shop/checkout
# etc. Top-level PHP files only.
RewriteCond %{REQUEST_METHOD} ^(?:GET|HEAD)$
RewriteCond %{THE_REQUEST} \s/+(.*/)?[A-Za-z0-9-]+\.php(?:[?\s]) [NC]
RewriteRule ^([A-Za-z0-9-]+)\.php$ $1 [R=302,L,NE]

# Internally serve extensionless top-level shop URLs from their PHP files.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([A-Za-z0-9-]+)/?$ $1.php [L,QSA]
