take the domain name 301 without www to the domain with www
RewriteEngine OnRewriteCond %{http_host} ^example.com$ [NC]RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
"RewriteEngine on",开启 Rewrite 规则开关;
"Rewritecond" refers to the overridden condition. The following string is matched by a regular expression, and the matching string begins with a ^ and ends with $. Here%{http_host} gets the current host name. The following rewrite rules are executed when the host name is example.com. where "[NC]" means case-insensitive;
"Rewriterule", define a rewrite rule. Here's what it means: Jump to "http://www.example.com/" next to the example.com in the URL of the access request. [r=301] refers to rewrite for 301 redirect/jump ([R] single-finger jump, meaning equivalent [r=302]), [L] refers to the last matching rule.
the old domain name 301 to the new domain name
Replace the domain name, the weight of the old domain can not be wasted, the old domain name of the top-level domain name and with the WWW domain name to 301 to the new domain name, the code is as follows
RewriteEngine OnRewriteCond %{http_host} ^(www.)?old.com$ [NC,OR]RewriteCond %{http_host} ^new.com$ [NC]RewriteRule ^(.*)$ http://www.new.com/$1 [R=301,L]
Now whether you visit old.com,www.old.com,new.com 301 to www.new.com is perfect enough! And all the inside pages will follow 301, then at least 2 months to wait, the period do not delete the original domain name, static weight completely transfer!
Note that WordPress By default does not support the command, because the WordPress URL itself is pseudo-static, in order to achieve this function, you must first make the inside page of wordpress HTML file.
Reprinted from: http://www.sjyhome.com/htaccess/301-redirect.html
. htaccess 301 REDIRECT Code