Nginx - domain forwarding

How can I redirect " http://domain.com ." " http://domain.com " with Nginx?

What is the recommended way to do this? Regex or are there any other options?

+5
source share
2 answers

The following snippet does this in a general way, without having to hardcode any host names (useful if your server configuration handles requests for multiple domains). Add this to any server definition you need.

if ($http_host ~ "\.$" ){
    rewrite ^(.*) $scheme://$host$1 permanent;
}

, $host , $http_host doesn (ta > tn > "; $http_host $host .

+13

Regex.

server {
    listen       80;
    server_name  domain.com.WHATEVER, domain.com.WHATEVER-2, domain.com.WHATEVER-3;
    rewrite  ^  $scheme://domain.com$request_uri?  permanent;
}

: http://wiki.nginx.org/HttpRewriteModule

redirect - 302; , http:// - 301

0

All Articles