0

I have a website with A records setup for the root domain and for the www subdomain.

My nginx vhost:

server {
        listen       80;
        server_name  www.example.com;
        return       301 http://example.com$request_uri;
}

server {

        server_name example.com;

        ...
}

When I visit the www site I expect to be redirected to the root domain - however, the www remains in the URL, no redirect occurs. The site loads as expected at the root domain and the www subdomain, but I'm looking for it to redirect.

3
  • Maybe my translation filter is failing me but when you’re trying to set up a redirect and then conclude “This works on desktop, although it does not redirect“ it simply does NOT work. - Also please note that 301 is a permanent redirect and (even when it is incorrect) it will be cached by browsers so keep that in mind. if you’re doing multiple tests please use new incognito/anonymous windows/tabs for each test. Check your web server logs to see if the 301 is sent, and if a redirected request arrives for the correct url or another
    – HBruijn
    Sep 12, 2018 at 17:57
  • Also note Chrome 69 breaks URLs by chopping off the "unimportant" bits, like "www." or "m.". Sep 12, 2018 at 18:12
  • 2
    Apologies @HBruijn - I meant the page loads, but the redirect does not occur. Both these comments were valid - my phone was indeed caching, the cache is a lot stickier than I had thought. I removed the nginx default site and restarted and the redirect now happens as expected. Many thanks.
    – Toby
    Sep 12, 2018 at 18:21

0

Your Answer

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

Browse other questions tagged or ask your own question.