RewriteEngine On

# ============================================
# DO NOT CHANGE index.php
# ============================================

RewriteRule ^index\.php$ - [L]


# ============================================
# REDIRECT OLD .PHP URLS
#
# /tools/calculator.php
#        ↓
# /tools/free-calculator-online
#
# /tools/qr-generator.php
#        ↓
# /tools/free-qr-generator-online
# ============================================

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


# ============================================
# INTERNAL REWRITE
#
# /tools/free-calculator-online
#        ↓
# /tools/calculator.php
# ============================================

RewriteRule ^free-(.+)-online/?$ $1.php [L,QSA]