How to fix 301 redirect with www

Posted April 16, 2020 475 views

Hello boss
my website host on nginx 14.1 server with ubuntu 18.4 i install ssl letsencypty by Certbot
this way sudo certbot --nginx -d -d
this is my file /etc/nginx/sites-available/

server {

    root /var/www/;

   index index.php index.html index.htm index.nginx-debian.html;
    location / {

            try_files $uri $uri/ /index.php?$args;

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;

            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;


    location ~ /\.ht {
            deny all;
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/; # ma$
ssl_certificate_key /etc/letsencrypt/live/; # $
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


server {
if ($host = {
return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = {
return 301 https://$host$request_uri;
} # managed by Certbot

   listen 80 default_server;
    listen [::]:80 default_server;
   return 301$request_uri;
return 404; # managed by Certbot

My website open 2 url look this and
but I want it open like this url please help how to fix
i am not developer Still work plz Show easy way

error chack this site

this error

Error - no preferred version www or non-www. Select one version as preferred version, then add a redirect https + not-preferred version to https + preferred version. Perhaps in your port 443 vHost something like “RewriteEngine on” + “RewriteCond %{SERVER_NAME} =” + “ReWriteRule ^{REQUEST_URI} [END,QSA,R=permanent]” (three rows, without the "). That should create a redirect https + ⇒ https + Or switch both values to use the non-www version as your preferred version.

Please help

edited by MattIPv4
Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!