In this case try the global :
server {
server_name "~^(?!www\.).*" ;
return 301 $scheme://www.$host$request_uri;
}
In this case try the global :
server {
server_name "~^(?!www\.).*" ;
return 301 $scheme://www.$host$request_uri;
}
You mean to put exactly like that on the block.
No create a file www-redirect.conf in /etc/nginx/conf.d with this content :
server {
server_name "~^(?!www\.).*" ;
return 301 $scheme://www.$host$request_uri;
}
[quote=βvirtubox, post:23, topic:9334β] No create a file www-redirect.conf in /etc/nginx/conf.d with this content :
disable all plugins which can impact the redirection : WP-Rocket, Wordfence, HideMyWP and any other plugin like that
All related plugins have been shut down. And cloudflare paused. But url still does not redirect.
Website do not work anymore but I was redirected to www.
Itβs working so I went to try another model.
When I put it like this it does not redirect the url https://chefclub.com.br/
to www.
I saw that several people could not do it the way it shows in the tutorial. He seems to be wrong about what I saw or obsolete according to the comments.
In this case do like that :
server {
server_name chefclub.com.br;
return 301 https://www.example.org$request_uri;
include /var/www/chefclub.com.br/conf/nginx/*.conf;
}
server { server_name www.chefclub.com.br; access_log /var/log/nginx/chefclub.com.br.access.log rt_cache; error_log /var/log/nginx/chefclub.com.br.error.log;
root /var/www/chefclub.com.br/htdocs;
index index.php index.html index.htm;
include common/php.conf;
include common/wpcommon.conf;
include common/locations.conf;
include /var/www/chefclub.com.br/conf/nginx/*.conf;
}
But "rewrite" is not a correct directive with nginx :
http://nginx.org/en/docs/http/converting_rewrite_rules.html
Strange he does not accept
return 301 https://www.example.org$request_uri;
have you set a server directive in another one ?
Itβs not like itβs always been
It only works that way! With only one block does not work you have to have both. But at least I was able to use the correct direction to redirect.
ssl-forcer
server {
listen 80;
server_name www.mysite.com.br chefclub.com.br;
return 301 https://www.mysite.com.br$request_uri;
}
block server
server {
server_name mysite.com.br;
return 301 https://www.mysite.com.br$request_uri;
access_log /var/log/nginx/mysite.com.br.access.log rt_cache;
error_log /var/log/nginx/mysite.com.br.error.log;
root /var/www/mysite.com.br/htdocs;
index index.php index.html index.htm;
include common/php.conf;
include common/wpcommon.conf;
include common/locations.conf;
include /var/www/mysite.com.br/conf/nginx/*.conf;
}
server {
server_name www.mysite.com.br;
access_log /var/log/nginx/mysite.com.br.access.log rt_cache;
error_log /var/log/nginx/mysite.com.br.error.log;
root /var/www/mysite.com.br/htdocs;
index index.php index.html index.htm;
include common/php.conf;
include common/wpcommon.conf;
include common/locations.conf;
include /var/www/mysite.com.br/conf/nginx/*.conf;
}