HTTPD's Domain name 301 jump

Source: Internet
Author: User
Tags response code

A site has multiple domain names, but to sub-primary and secondary, so with 301来 permanent jump, 302 means temporary jump.

method One, rewrite, involving modules mod_rewrite

<ifmodule mod_rewrite.c>
Rewriteengine on
Rewritecond%{http_host}!^www.sunnysky.com$

Rewriterule ^/(. *) $ http://www.sunnysky.com/$1 [r=301,l]
</IfModule>

Or

<ifmodule mod_rewrite.c>

Rewriteengine on

Rewritecond%{http_host} ^www.byqk.com$ [OR]

Rewritecond%{http_host} ^www.a.com$

Rewriterule ^/(. *) $ http://www.sunnysky.com/$1 [r=301,l]

</IfModule>


<ifmodule mod_rewrite.c>

Rewriteengine on

Rewritecond%{http_host} ^cmp.soso.com [NC]

Rewriterule ^/js/(. *) http://www.soso.com/js/$1 [r=301]

</IfModule>

Redirect All Access under the JS directory in cmp.soso.com to http://www.soso.com/js/, specifying a jump return code of 301.


Method Two,Redirect, involving modules: Mod_alias

<virtualhost 10.1.146.163:80>

documentroot/home/qmhball/web/mybranches/stat_3276/oa/

ServerName oalogin.com

Redirect 301/login.php http://www.soso.com

</VirtualHost>

REDIRECT access to login.php under Oalogin.com to http://www.soso.com , return code 301.
If you do not specify a return parameter for redirect (301 in the example), the default redirect is "temporary" (HTTP status 302).


Test effect

# curl-x192.168.18.20:80 www.a.com/c-I.
<! DOCTYPE HTML PUBLIC "-//ietf//dtd HTML 2.0//en" >

<title>301Moved permanently</title>


<p>the document has moved <a href= "Http://www.sunnysky.com/c">here.
</body>


The difference between 301 and 302 in the HTTP return code

one. Official statement
      301,302  is the encoding of the HTTP state, which means that a URL has shifted, except that: &NBSP;
     301  redirect: 301  represents permanent transfer (permanently moved).
     Span style= "Font-family:consolas;" >302 redirect: 302  represents a temporary transfer (temporarily moved ). &NBSP;

Two The difference in reality
2.1. For user
    301,302 is no different to the user, they see the effect is just a jump, the old URL in the browser becomes the new URL. The page jumps to the place where this new URL points.
2.2. For engine and webmaster
2.2.1 302
    302 The steering may have URL normalization and URL hijacking issues. May be judged by search engines as a suspicious turn, or even as cheating.
URL Normalization
    See also:http://www.chinamyhosting.com/seoblog/2006/04/10/url-canonicalization/
URL Hijacking
    What does 302 redirect and URL hijacking (URL hijacking) matter? This is going to start with how the search engine handles 302 turns. From the definition of a 302 redirect to URL b from URL A, the host server implies that URL a may change its mind at any time, re-display its own content or move to another place. Most of the search engines in most cases, when received 302 redirect, generally as long as to crawl the destination URL, that is, url B.
    In fact, if the search engine encountered 302 turn, 100% of the target URL b crawl, you do not have to worry about URL hijacking. The problem is that sometimes search engines, especially Google, don't always crawl the target URLs. Why is it? For example, sometimes a URL is very short, but it does a 302 redirect to the B URL, and the B URL is a long, messy URL, and may even contain some questions such as question marks. Naturally, a Web site is more user-friendly, while the B URL is both ugly and user-friendly. It is likely that Google will still show URL a.
    because the search engine ranking algorithm is only a program and not a person, in the face of 302 redirects, and can not be like a person to determine exactly which URL is more appropriate, which resulted in URL hijacking the possibility. That is, an immoral person in his own URL A to do a 302 redirect to your URL B, for some reason, Google search results are still displayed in URL a, but the content of the Web page is your URL B is the content, this is called URL hijacking. Your hard-earned content was stolen by others.

2.2.2 301
When page A is redirected to page B with a 301 redirect, the search engine can confirm that page a permanently changes position, or that it does not exist, and that the search engine will treat page B as the only valid target.
The 301 benefits are:
First, there is no URL normalization issue.
Second, it is also important that page A's PR page level will be uploaded to page b.


' redirect| R [=code] ' detailed
A substitution that is prefixed with http://thishost[:thisport]/(making the new URL a URI) can be forced to perform an external redirect.

If code is not specified, an HTTP response code of 302 (temporary move) is generated.

If you need to use a different response code in the 300-400 range, just specify this value here,

Alternatively, you can use one of the following symbol names: Temp (default), permanent, seeother. Use it to feed the normalized URL back to the client, such as "/~" to "/u/", or to/u/user with a slash Wait a minute.


Attention

When using this tag, you must make sure that the replacement field is a valid url! otherwise, it will point to an invalid location! And remember, this tag itself is just a prefix to the URL plus http://thishost[:thisport]/, The rewrite operation will still continue. In general, you will want to stop the rewrite operation and immediately redirect, then you also need to use the ' L ' tag.

Add:http://blog.csdn.net/qmhball/article/details/7838989

This article is from the "Hiyang" blog, make sure to keep this source http://hiyang.blog.51cto.com/10728919/1786214

HTTPD's Domain name 301 jump

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.