Options -Indexes
RewriteEngine On

# Do not rewrite real files/folders such as assets/css/style.css, admin/, ajax/, uploads, etc.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Clean country/state/city marketplace URLs
RewriteRule ^([a-z0-9-]+)/?$ country.php?country=$1 [L,QSA]
RewriteRule ^([a-z0-9-]+)/browse/?$ browse.php?country=$1 [L,QSA]
RewriteRule ^([a-z0-9-]+)/browse\.php/?$ browse.php?country=$1 [L,QSA]
RewriteRule ^([a-z0-9-]+)/companies/?$ companies.php?country=$1 [L,QSA]
RewriteRule ^([a-z0-9-]+)/companies\.php/?$ companies.php?country=$1 [L,QSA]
RewriteRule ^([a-z0-9-]+)/listing/([0-9]+)/?$ listing.php?id=$2&country=$1 [L,QSA]
RewriteRule ^([a-z0-9-]+)/company/([0-9]+)/?$ company.php?id=$2&country=$1 [L,QSA]
RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/?$ state.php?country=$1&state=$2 [L,QSA]
RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/([a-z0-9-]+)/?$ city.php?country=$1&state=$2&city=$3 [L,QSA]

<FilesMatch "(^config\.php|\.sql|\.log)$">
  Require all denied
</FilesMatch>
