I am trying to convert:
To either
or
Depending on which is simpler to do or faster
This works for the index page but for subfolders and files it gets in a redirect loop.
server {
listen 80;
# Make site accessible from http://localhost/
server_name ~^[^.]+.example.com$;
rewrite ^/(.*)/$ /$1 permanent;
if ($host ~* ^([^.]+).example.com$) {
set $subdomain $1;
}
rewrite ^(.*)$ $1?subdomain=$subdomain last;
location / {
root /var/www/example.com;
index index.html index.php;
}
location ~ \.php$ {
try_files $uri =404;
root /var/www/example.com;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script
include fastcgi_params;
}
}