. htaccess 301 REDIRECT Code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.