301 Redirect is not unfamiliar, sometimes there is a need to redirect a directory whole to a level two domain name, or the top-level domain request without WWW is all redirected to the two-level domain name with www. If it is Apache, it needs to be configured. Htaccess,nginx is not supported and needs to be implemented using rewrite directives in the configuration file.
Top-level domain name redirect to www
Copy Code code as follows:
server {
server_name jb51.net;
Rewrite ^/(. *) $ http://www.jb51.net/$1 permanent;
}
As configured on, so jb51.net requests will be redirected to the www.jb51.net,301 redirect is helpful for SEO. This configuration is used by most people.
www level two domain name redirect to top-level domain
Copy Code code as follows:
server {
server_name www.jb51.net;
Rewrite ^/(. *) $ http://domain.com/$1 permanent;
}
Rivers and lakes are rumored that the weight of the top-level domain name than the WWW two domain name is high, some seoer will require the operation dimension must be transferred to the WWW request to the top-level domain name, and the above practice is the opposite.
Directory redirection
Copy Code code as follows:
if ($request _filename ~ nginxjiaocheng/) {
Rewrite ^ http://www.jb51.net/nginx/? permanent;
}
directory jump new domain name
Copy Code code as follows:
if ($request _filename ~ nginx/) {
Rewrite ^ http://nginx.jb51.net/? permanent;
}
Nginx This column is too hot, intend to specially get a domain name.
With: Domain name between the 301 jump and test methods
One, the same root domain name and the sub domain name jumps between
The first case: access to the root domain name redirect to the www subdomain (vhost is usually bound by a number of domain names, this can be precisely positioned to a domain name, does not cause the domain name to jump to this domain name)
server {
server_name www.jb51.net jb51.net;
if ($host = ' jb51.net ') {
Rewrite ^/(. *) $ http://www.jb51.net/$1 permanent;
}
Two, the different domain name between 301 jumps
The first case: access to a station to B station
Copy Code code as follows:
server {
server_name www.jb51.net;
Rewrite ^ (. *) http://www.jb51.net$1 permanent;
}
In the second case: not all redirects to the a station to the specified page
Copy Code code as follows:
server {
server_name www.jb51.net;
if ($host!= ' jb51.net ') {
Rewrite ^/(. *) $ http://www.jb51.net/$1 permanent;
}
}
If you write in the first server segment
will also be redirected when using IP access
301 REDIRECT status on-line detection tool: http://web-sniffer.net/
The return of this sentence is only 301 redirect success:
Copy Code code as follows:
status:http/1.1 Moved Permanently