How do PHP and ASP programs make 301 settings?

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

301 is an important part of the site optimization, you can focus on the home page weight, you can also change the domain name in the site or the revision, the original weight of the focus of the transfer to the new URL, to prevent the error page, avoid the original weight ranking loss. The following Changde SEO is mainly for the virtual host, if the server or VPS, you can set up in the ISS, the method is relatively simple.

PHP Program 301 Settings

To change the space of the program (in Win2003 system space for example) you must open the ISAPI rewrite before you can make the following settings, 301 to be effective. When turned on, copy the following code into Notepad, save as. htaccess, and upload the. htaccess file to the root directory of the Web site space.

1, focus on the home page weight

Redirect "domain.com" 301 without www to the "www.domain.com" domain name with www

The first method:
Rewriteengine on
RewriteCompatibility2 on
Repeatlimit 200
Rewritebase
Rewritecond%{http:host} ^domain.com$
Rewriterule (. *) http://www.domain.com$1 [nc,r=301]
The second method:
Rewriteengine on
Rewritecond%{https} (ON)?
Rewritecond%{http:host} ^ (?! www.) (. +) $ [NC]
Rewritecond%{request_uri} (. +)
Rewriterule.? HTTP (?%1s)://www.%2%3 [r=301,l]

2, site replacement domain name

For example, Wujiangda oven a number of domain names, the need to be a number of domain names for the unification, user-friendly browsing, so that other Wujiang oven's secondary domain name can be redirected to a primary domain name with 301.

Rewritecond%{http:host} ^www.domain.com.cn$
Rewriterule (. *) http://www.domain.com$1 [nc,r=301]

3, the website revision,

The internal URL changes, you can bulk 301 redirect to the new URL.

Rewriterule ^/oldpage.htm$ http://www.domain.com/newpage.html [r=301,l]

Second, the ASP program 301 settings

1. Home redirect

ASP program set 301 relatively simple, put the following code on the homepage of the site (generally more index.asp on the directory) can begin. This method can be set up a variety of situations, can be redirected without www to the world with WWW, other secondary domain name redirect to the main push domain name.

<%
Website=request. ServerVariables ("SERVER_NAME")
' Get the domain name of the current access
If website= "domain.com" Then
' Judge if your domain name is not with WWW domain name
Response.status= "Moved Permanently"
Response.AddHeader "Location", "http://www.domain.com/"
' Do 301 redirect to domain name with www
End If
%>

2. Using Web.config to realize

<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name= "WWW Redirect" stopprocessing= "true" >
<match url= ". *"/>
<conditions>
<add input= "{http_host}" pattern= "^$"/>
</conditions>
<action type= "Redirect" Url= "http://www/{r:0}"
Redirecttype= "Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Copy the following code into Notepad and save it as web.config, and then upload the Web.config file to the root directory of the site space.

The above Changde SEO simply introduced several more common 301 redirect settings, of course, there are many other ways to set up, here is not one to repeat, if you have any good method, may wish to take out you share!

Article source: This article by Wujiangda Oven official website http://www.wjdadehx.com/'s partner Changde SEO provides, the copyright notice: Welcome free reprint, reprint, please retain the original author information, thanks the cooperation!

Related Article

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.