0

I have a multisite installation that runs on Nginx.

In my site's configuration file, I have set the server block as:

server{
        listen 80 default_server;
        server_name example.com *.example.com;
        server_name_in_redirect off;

        access_log   /var/log/nginx/example.com.access.log;
        error_log    /var/log/nginx/example.com.error.log;

        root /var/www/example.com/htdocs;
        index index.php;

        if (!-e $request_filename) {
                rewrite /wp-admin$ $scheme://$host$uri/ permanent;
                rewrite ^(/[^/]+)?(/wp-.*) $2 last;
                rewrite ^(/[^/]+)?(/.*\.php) $2 last;
        }

        location / {
                try_files $uri $uri/ /index.php?$args;
        }
}

Right now, whenever I enter www.example.com in the browser, I get redirected to example.com.

However, I want example.com to redirect to www.example.com.

I also plan to use HTTPS with www.example.com

What else do I need to add to my configuration file to make this happen?

0

Your nginx configuration is fine, you just need to edit the site name in your Multisite settings in the Sites section, and perhaps run a search-replace across the entire database to replace non-www with www links. I'm not sure, but you might additionally need to create a redirect for your non-www domain, although last time I tried that it magically worked on its own.

That said, the only legit reason to use WWW is when a service won't host your DNS or you choose not to host your DNS with that service, and the DNS is dynamic due to load balancing and whatnot. In that case the only option is to use a CNAME entry, and CNAME entries can only be applied to subdomains. Google App Engine was like this for a very long time until they started hosting DNS for their customers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.