简体   繁体   中英

Nginx redirect top level domain

I've just started using Nginx instead of apache.

I'm trying to find a similar way to do something like this, in Apache:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?example\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

But in Nginx.

So basically any .co.uk traffic gets redirected to .com

You could create a separate server block for the .co.uk domain:

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

See this document for details. Note that the default_server option can also be used to match any non-specific domain name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM