0

I want to redirect my domain example.com to www.example.com

My /etc/nginx/sites-available/example.com configuration is

server {
    listen 80;
    listen [::]:80;

    root /var/www/example.com/html;
    index index.php index.html index.htm;

    server_name example.com www.example.com;

    location / {
                 try_files $uri $uri/ /index.php?q=$request_uri;               
                }

error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /usr/share/nginx/html;

}

What changes should I do in this code?

I have added this line : try_files $uri $uri/ /index.php?q=$request_uri;

for wordpress permanent link correction.

matt
  • 11
  • 1

2 Answers2

1

You need a separate server block to listen for the non www and 301 it to www like this

server {
    listen 80;
    server_name netmark.com;

    return 301 $scheme://www.netmark.com$request_uri;
}
Brian Bowles
  • 331
  • 1
  • 5
0

You can read this tutorial to move a domain to another domain but from what I understand you only want to change the actual domain prefix.