MODX Revolution 2.4.0-pl
Hi Guys how can I alter the code at
https://docs.modx.com/revolution/2.x/getting-started/installation/basic-installation/nginx-server-config
...to redirect from example.com to www.example.com
The code:
server {
listen 80;
server_name example.com www.example.com;
root /home/sites/example.com;
index index.php;
client_max_body_size 30M;
location / {
root /home/sites/example.com;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_ignore_client_abort on;
fastcgi_param SERVER_NAME $http_host;
}
location ~ /\.ht {
deny all;
}
}
I've tried adding:
if ($host = "example.com") {
rewrite ^ $scheme://www.example.com$request_uri permanent;
}
location / {
try_files $uri $uri/ @modx-rewrite;
}
...from
https://support.modx.com/hc/en-us/articles/217295387-Nginx-Web-Rules-Rewrites ...but no luck as I get the error "ERR_TOO_MANY_REDIRECTS" in Chrome.
and also tried
return 301 $scheme://www.example.com$request_uri;
...from
https://www.nginx.com/blog/creating-nginx-rewrite-rules/ ...but no luck as I get the error "ERR_TOO_MANY_REDIRECTS" in Chrome.
Any ideas please?
Thanks