W
W
Win32Sector2017-04-28 18:10:52
Nginx
Win32Sector, 2017-04-28 18:10:52

How to rewrite from subdomains?

Good afternoon, comrades, help, please.
The situation is as follows: there is this code in the nginx virtual host config:

if ($http_host = site.com) {
      
        rewrite  ^(/)$ https://www.site.com$1 permanent;
        rewrite  ^(/docs.*)$ https://www.site.com$1 permanent;

        rewrite  ^(/books.*)$ https://example.com$1 permanent;
        rewrite  ^(/nature.*)$ https://example.com$1 permanent;
        rewrite  ^(/science.*)$ https://example.com$1 permanent;
       
    }

That is, the code redirects requests like site.com/books/book1 to example.com/books/book1
And how can I redirect subdomains like test.site.com/books/book1 ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nurlan, 2017-05-03
@Win32Sector

I think this will be enough for you to cope:
How to redirect from a subdomain to an NGINX folder?
How to replace subdomain in http header in nginx?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question