RewriteEngine On

# ==========================================
# KSQUARE LOGISTICS
# ==========================================


# ------------------------------------------
# Redirect index.php to homepage
# ------------------------------------------

RewriteCond %{THE_REQUEST} \s/+ksquarelogistics/index\.php(?:[\s?]|$) [NC]
RewriteRule ^index\.php$ /ksquarelogistics/ [R=301,L]


# ==========================================
# FORM HANDLERS
# DO NOT REDIRECT THESE PHP FILES
# ==========================================

RewriteRule ^sendmail\.php$ - [L]
RewriteRule ^quote-sendmail\.php$ - [L]
RewriteRule ^newsletter-sendmail\.php$ - [L]

# ------------------------------------------
# Redirect other .php URLs to clean URLs
# ------------------------------------------

RewriteCond %{THE_REQUEST} \s/+ksquarelogistics/(.+)\.php(?:[\s?]|$) [NC]
RewriteRule ^(.+)\.php$ /ksquarelogistics/$1 [R=301,L,NE]


# ------------------------------------------
# Clean URL -> PHP
# ------------------------------------------

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/ksquarelogistics/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]