301 redirection and URL Forwarding

Source: Internet
Author: User
Tags domain name registration subdomain name url forwarding
You can use the url forwarding feature (url-forwarding or urlredirect) implemented by the server technology to forward it to a domain name with www for access. However, we have mentioned that using this url forwarding method is not good for seo. the most friendly jump method for search engines is using 301 redirection (also called 301 redirection and 301 redirection ). So here we have some questions, why does godaddy and other domain name registrar provide ur

When purchasing a domain name, the domain name itself does not contain www, but because the domain name can only be used after resolution through the DNS server, in this process, each domain name is directed to a web server IP address, since a long time ago, the website side added a "www" subdomain name to help customers access the website with more paths, the customer usually follows: "www. ++. com. ++. com is not accessible. for customers who do not understand the technology or DNS, this problem may cause him to be unable to access your website, because he only knows to access your site in the form of "www", he may not know "++. com "is also accessible! Therefore, more people are continuing this practice. when we buy a domain name for a space, the service provider will also help you with the "www" resolution. of course, the server address for this resolution is the same as that for "www". Therefore, you can access the same content simultaneously with or without two domain names. To put it bluntly, the answer to this question is: allow people who use the Internet for the first time to access your website faster.

In this case, the traffic and PR values of a domain name will be dispersed. it is best to direct all access requests to a domain name.

You can use the url forwarding feature (url-forwarding or url redirect) implemented by the server technology to forward it to a domain name with www for access. However, we have mentioned that using this url forwarding method is not good for seo. the most friendly jump method for search engines is using 301 redirection (also called 301 redirection and 301 redirection ).

So I have some questions here. why is the url forwarding function provided by domain name registrars such as godaddy not conducive to seo? What is the principle of url Forwarding? If you want to use 301 redirection, how do you set Linux apache, Windows IIS, php, ASP, ASP. NET, and JSP to implement 301 redirection respectively?

301 role of redirection

Why use 301 redirection? The first article is what we mentioned just now for seo optimization. we also mentioned in how to normalize URLs. after 301 redirection is set, the original page will return the 301 HTTP status code to the browser or search engine, notify the search engine that the next page has been permanently redirected to a new page. the spider will not index the original page, and will also pass the PR weight of the original page to the new page to jump. If the 302 status code is returned, it indicates that the spider page jump is only temporary and the spider will still Index The original page, which causes duplicate page problems (that is, Google supplementary materials ). For example, when www.nowamagic.net 302 is redirected to nowamagic.net, they are treated as two duplicate pages.

Second, if you want to change the domain name for various reasons, you can use 301 redirection to redirect the old domain name 301 to the new domain name, so that the traffic of the old domain name will not be lost, and the PR weight will also be transferred. In addition, if you have registered multiple domain names and direct them to the same website, you can also set only one primary domain name and set other domain names to 301 to the primary domain name, in this way, each domain name will not distribute weights. Therefore, it is necessary to use 301 redirection.

Principles of URL Forwarding

There are two methods for url Forwarding: hide forwarding and (the url entered in the address bar of the browser after url forwarding remains unchanged) hide forwarding (also called explicit forwarding: after the url is forwarded, the address displayed in the address bar is the forwarded url ). Someone has tested whether to hide or not. different domain name registration service providers may return different http headers. Some domain name service providers set the url Forwarding function (URL Forwarding) in the management background will cause the server to return a 302 status code to the search engine, rather than a 301 http status code.

It is said that some of these types of url Forwarding are implemented by applying an iframe framework to the browser window to implement hidden forwarding, while others are using Javascript or Meta Refresh to implement url forwarding without hiding, the 301 redirection method is rarely used. Therefore, we should try to use the url forwarding function as little as possible. Instead, we should manually set it to implement 301 redirection.

How to implement 301 redirection

We have mentioned many settings for WordPress and other 404 pages. There are also many implementation methods for setting 301 redirection (301 redirection, redirection). The following lists various 301 redirection implementation codes based on different space server Types and Programming Languages, for reference, check the pair number for the children's boots:

Mod-Rewrite mode on the Apache server on the Linux host: use the. htaccess file

When a browser or search engine spider sends a page request, the Web server will check a request named '. htaccess' file, which specifies how to process page requests by modifying the settings '. the htaccess' file tells the search engine whether a page is 302 redirection (temporary redirect) or 301 redirection (permanent redirect ). Some Linux host servers also support direct 301 redirection in the management background. If it cannot be set in the background, the process of implementing 301 redirection is also very simple: create a new file named .htaccess.txt (note that the previous vertex number cannot be omitted), and write the following 301 redirection code in the txt file:

Options +FollowSymLinksRewriteEngine onrewritecond %{http_host} ^nowamagic.net [nc]rewriterule ^(.*)$ http://www.nowamagic.net/$1 [r=301,nc]

Or

RewriteEngine OnRewriteCond %{HTTP_HOST} !^nowamagic.net$ [NC]RewriteRule ^(.*)$ http://www.nowamagic.net/$1 [L,R=301]

Save the file, remove the txt file with the last name, and upload it to the root directory of the website. The above code indicates that all webpages with www.nowamagic.net addresses on the entire site will be directed to nowamagic.net without www (not only the home page, but also the subdirectories/webpages ). If other domain names are redirected to the new domain name nowamagic.net, add the following redirection code to the. htaccess file:

Options +FollowSymLinksRewriteEngine onRewriteRule ^(.*)$ http://www.nowamagic.net/$1 [L,R=301]

301 redirection settings under IIS on Windows host

In the IIS management background-> select the file or folder you want to redirect-> right-click "redirect to URL"-> enter the target URL to redirect-> Select "permanent resource redirect ".

In addition, if your Windows virtual host space supports ISAPI_Rewrite, you can use ISAPI_Rewrite in IIS to not only implement url rewriting, but also set 301 redirection, the following figure shows the code for converting the www-based domain name 301 corresponding to ISAPI_Rewrite of the three versions to the code without the www domain name:

# ISAPI_Rewrite 1.3 domain name 301 redirection RewriteCond Host: ^ www \. farlee \. info $ RewriteRule (. *) http \: // farlee \. info $1 [I, R] # ISAPI_Rewrite 2.x version RewriteCond Host: ^ www \. farlee \. info $ RewriteRule (. *) http \: // farlee \. info $1 [I, RP] # ISAPI_Rewrite 3.x version RewriteCond % {HTTP: Host} ^ www \. farlee \. info $ RewriteRule (. *) http \: // farlee \. info $1 [NC, R = 301]

In other cases, for example, the 301 redirection code between different domain names in IIS, see details: ISAPI Rewrite implements IIS 301 redirection.

PHP 301 redirection code

301 redirection can also be implemented by adding a php header to the php file. the code is as follows:

 

ASP 301 redirection code

<%@ Language=VBScript %><%Response.Status="301 Moved Permanently"Response.AddHeader "Location", http://nowamagic.net%>

ASP. NET 301 redirection 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.