RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]+)\.([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ %2/%1/$1 [R=301,L]
* IN A 192.168.1.1
<VirtualHost *:80>
DocumentRoot /path/
ServerName example.com
ServerAlias *.example.com
server_name .example.com