为什么需要使用301重定向:
1. 保留搜索引擎的排名: 301 重定向是最有效的方法,不会影响到搜索引擎对页面的排名。
2. 保留访客和流量: 如果你将页面链接到大量方法可以访问过的地址,如果不是用重定向的话你就会失去这些用户(不解)原文:If you move your popular page to which a lot of visitors have already linked, you may lose them if you don't used redirect method. This provides a great way to provide your visitors with the information they were looking for and prevent you from losing your traffic.
下面是 11 中实现 301 重定向的方法:
1. HTML 重定向/Meta 刷新
将下面 HTML 重定向代码放在网页的 <head> 节点内:
<meta HTTP-EQUIV="REFRESH" content="0; url=http:///$1 [r=301,nc]
注意: .htaccess 方法的重定向只能在 Linux 下使用 Apache 的 mod_rewrite 模块启用的情况下使用。
12.Nginx中的rewrite
复制代码 代码如下:
server {
server_name www.jb51.net jb51.net;
if ($host = 'jb51.net' ) {
rewrite ^/(.*)$ https://www.jb51.net/$1 permanent;
}