How to fix 200 and 301 redirect

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 godsunsat.com -d www.godsunsat.com
this is my file /etc/nginx/sites-available/example.com

server {

    root /var/www/godsunsat.com/public_html;
    
   index index.php index.html index.htm index.nginx-debian.html;
    server_name www.godsunsat.in godsunsat.com;
    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/www.godsunsat.com/fullchain.pem; # ma$
ssl_certificate_key /etc/letsencrypt/live/www.godsunsat.com/privkey.pem; # $
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
if ($host = www.godsunsat.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

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

   listen 80 default_server;
    listen [::]:80 default_server;
    server_name www.godsunsat.com godsunsat.com;
   return 301 https://www.godsunsat.com/$request_uri;
return 404; # managed by Certbot

}

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

Hi @mrkumar

please read the output of your domain check - https://check-your-website.server-daten.de/?q=godsunsat.com

There is already a sample you may use.

I did not find this code in which file I would look and change
Specify file path

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} = example.com" + "ReWriteRule ^ https://www.example.com%{REQUEST_URI} [END,QSA,R=permanent]" (three rows, without the "). That should create a redirect https + example.com ⇒ https + www.example.com. Or switch both values to use the non-www version as your preferred version.

As written. That’s your server. If you use WordPress, you may have to do that in your WordPress configuration.

ok i chack it please wait…

my wp-confi all right but
I do not know how to correct this, change the file from which angle

I don't use WordPress.

But WordPress should have an option to select the preferred version non-www or www.

Selecting that option should add a (system-) correct and search-engine safe redirect.

Mixing raw solutions (explicit server configurations) and solutions from CMS is always critical.

1 Like

It's done i'll be grateful to you

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.