Previously, Zhang xiaosan also summarized the tutorial of domain name 301 redirection, but it was messy. This time, I re-arranged it, in a simple and efficient nginx and apache environment, we strive to Redirect 301 domain names without WWW to domain names with WWW.
There are three methods for 301 redirection of nginx domain name:
Native nginx later versions support:
Server {
Server_name 111cn.net;
Return 301 http://www.111cn.net $ request_uri;
}
Rewrite nginx general support:
Server {
Server_name 111cn.net;
Rewrite ^ (. *) http://www.111cn.net $1 permanent;
}
Judge the rewrite method:
If ($ host! = 'Www .111cn.net '){
Rewrite ^/(. *) $ http://www.111cn.net/#1 permanent;
}
Apache domain 301 Redirection. htaccess
Method 1:
Options + FollowSymLinks
RewriteEngine on
RewriteRule (. *) http://www.111cn.net/#1 [R = 301, L]
Method 2:
RewriteEngine On
RewriteCond % {HTTP_HOST} ^ 111cn.net/[NC]
RewriteRule ^ (. *) $ http://www.111cn.net/#1 [L, R = 301]