D
D
Desa0072021-04-12 18:24:16
Nginx
Desa007, 2021-04-12 18:24:16

Nginx How to make a redirect from www group of domains?

There are several domains that stubs for the site cling to.
The task is to redirect from www.example.(de|es|ch|uk|eu|ru|nl|pl|us|fr|jp|co|hk|in|it) to example.(de|es|ch|uk |eu|ru|nl|pl|us|fr|jp|co|hk|in|it).

server directory example:

server {
        listen 80;
        listen         [::]:80;
        server_name    ~^www\.example\.(de|es|ch|uk|eu|ru|nl|pl|us|fr|jp|co|hk|in|it)$;
        rewrite ^(.*) http://example.??$1 permanent;
    }


Is it possible to do such a redirect without writing each domain separately? There is a list of domains, you need to set up a redirect from www. Is it possible?
server {
listen 80;
listen[::]:80;
server_name ~^www\.example\.(de|es|ch|uk|eu|ru|nl|pl|us|fr|jp|co|hk|in|it)$;
rewrite ^(.*) example.??$1 permanent;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-04-12
@Desa007

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

        server_name    ~^www\.(?<mydomain>example\.(?:de|es|ch|uk|eu|ru|nl|pl|us|fr|jp|co|hk|in|it))$;
        rewrite ^(.*) http://$mydomain$1 permanent;
}

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

        server_name    ~^www\.(example\.(?:de|es|ch|uk|eu|ru|nl|pl|us|fr|jp|co|hk|in|it))$;
        return 301 http://$1$request_uri;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question