nginx directory to automatically add a slash "/"

The default configuration when you visit http://abc.example.com/dir  time will not add "/"

common practice 

     if (-d $request_filename){
  rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
      }

 

Better alternative

optimize_server_names off; # optimizing server name: Off
server_name_in_redirect off; # redirection server name: Off

http://wiki.codemongers.com/Ngin ... timize_server_names

 

The best way is added at http server or the nginx.conf

http {
...
server_name_in_redirect OFF;
...
}

official http://wiki.nginx.org/NginxHttpCoreModule#optimize_server_names Description

Note: the this Directive IS  deprecated  in Nginx 0.7.x , use  server_name_in_redirect  iNSTEAD.
Remarks this command nginx 0.7.x is no longer supported, instead of using server_name_in_redirect

domestic two ways to search
the first method  with the rewrite fill /
IF (-d $ request_filename) {rewrite ^ / (. *) ( [^ /]) $ / $ 1 $ 2 / permanent;}

the second method
optimize_server_names OFF;  
#optimize_server_names has not supported me in nginx 0.8 plus this will complain
server_name_in_redirect off;

Guess you like

Origin www.cnblogs.com/webenh/p/12079594.html