N
N
nikita-slb2016-11-23 23:59:30
Nginx
nikita-slb, 2016-11-23 23:59:30

How to make a redirect in nginx with a change of address in the address bar?

There is a site, I set up a 301 redirect from www to without www in nginx.
All headers are returned correctly, but is it possible to somehow set up a redirect so that after entering www.site.com in the address bar, it will be replaced with site.com.
That is, similar to how it would be if you use a redirect using php

server {
    listen IP:80;
    server_name www.site.com;
    return 301 $scheme://site.com$request_uri;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2016-11-24
@nikita-slb

This is how it should happen - this is how redirects work, what return 301 {to}, what rewrite {from} {to} permanent. They tell the client to send a new request to a new URL, which the client does.
If you still have the old url - something is wrong with the configuration elsewhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question