Focus on cloud service provider activities
Notes on website operation and maintenance

LNMP Series Tutorial 5: How to Set 301 Redirection

because LNMP The system environment uses Nginx instead of Apache, so you can set the three hundred and one When redirecting, it is not simple to add code in the root directory. htaccess file, because it needs to modify the configuration of the separate website conf file. Some friends want to say why WordPress does not need to be set. Because of the particularity of the program, we choose to set up a blog with or without WWW, and then the other will automatically redirect internally.

If you are in another program, you need to set it manually. The specific methods are as follows:

First, under/usr/local/nginx/conf/vhost/in our VPS, we will see the CONF file named by the domain name of our website, and then we can modify it with the VI command, or use FTP to download it to the local location for modification and then upload it;

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

The above is revised. You can make up for what you lack after comparing it. Because I am afraid that people will put it in the wrong place, I copy the front and rear codes.

Step 2, we restart LNMP The adopted commands are as follows:;

/root/lnmp restart

In this way, you can enter the domain name without WWW through the website, and whether to jump to the domain name with WWW directly. If you are not sure, you can also check whether it is correct through the webmaster tool.

Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » LNMP Series Tutorial 5: How to Set 301 Redirection


Scan the code to follow the official account

Get more news about webmaster circle!
Entrepreneurship, operation and new knowledge