RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond "%{HTTP_USER_AGENT}" "^Vtech Hotelphone.*?([0-9a-fA-F]{12})$" [NC]
RewriteRule ^(.*)$ index.php?filename=$1&mac=%1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?([0-9a-fA-F]{12}).*) index.php?filename=$1&mac=$2 [L]

# Special rule for MultiCell configs that don't have MAC in the filename
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(MultiCell_[0-9]+\.cfg)$ index.php?filename=$1 [L]

# Special rule for Xorcom Gateway configs with format XX/default.xml
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/default\.xml$ index.php?filename=default.xml [L]