0

I need to forward all visitors from "domain.com" to "www.domain.com".

I know this has something to do with altering the nginx config file but am not sure what to do or what code to use.

I am using nginx as the server.

Any help would be appreciated :)

3 Answers3

1

In my own NGINX setup, I made a separate vhost for domain.com:

server {
  listen   1.2.3.4:80;
  server_name  domain.com;
  rewrite  ^(.*) http://www.domain.com$1 permanent;
}
Sgaduuw
  • 1,823
  • 12
  • 16
0

Apparently I can't just have a link as an answer...

Anyway, check out this question: Nginx: Forward all Subdomains

The config there should work for you.

yrosen
  • 283
  • 1
  • 6
0

You can rewrite the URL in the config file like this:

server {
    server_name  domain.com;
    rewrite ^(.*) http://www.domain.com$1 permanent;
}

server {
    server_name  www.domain.com;
    #My other config options
}
Bart De Vos
  • 17,761
  • 6
  • 62
  • 81