The method to set 301 redirection in the LNMP series

  • 2020-05-06 12:05:49
  • OfStack

Some friends have said why wordpress does not need to be set, because of the special nature of the program, we choose to set up a blog with WWW or without WWW, and then the other one will be automatically redirected internally.

If you are another program you need to set it up manually. Here's how:

In the first step in our VPS/usr/local/nginx/conf/vhost /, we will see our website domain name CONF file, which can then be VI command to change, also can use FTP downloaded to the local modifications to pass up;

 
server_name www.laozuo.org laozuo.org; 
if ($host !=  ' www.laozuo.org' ) { 
rewrite ^/(.*)$ http://www.laozuo.org/$1 
permanent; 
} 
index index.html index.htm index.php default.html default.htm default.php; 


The above is modified, you compare, you lack, and then you can make up. Because I don't want people to put it in the wrong place, so I copied the code before and after.

Second, we restart LNMP with the following command;

 
/root/lnmp restart 


In this way, you can enter the domain name without WWW through the url, whether to jump directly to the domain name with WWW. You are not at ease, also can check through stationmaster tool is correct.

Related articles: