Through the htaccess file to achieve SEO optimization results collection

Source: Internet
Author: User
Keywords SEO

Intermediary transaction SEO diagnosis Taobao guest Cloud host technology Hall

htaccess files have always been a good SEO experts at home and abroad a careful study of a file, because the file in many cases to take over the site's highest configuration (such as virtual host), If you can reasonably use the good. htaccess file, not only can achieve the unexpected SEO effect, but also can solve a lot of problems related to the site.

The. htaccess file is exactly the file below the Linux system, as can be seen from its filename. And this file has a strict encoding and format, one more space and less than one space can cause the server 500Error, therefore, we do not recommend using the Windows system with Notepad to edit the file. The best manual editing method is to use an advanced text editor such as UE or NOTEPAD2. If you are not convenient to download or manually write the file error, also highly recommend the online htaccess text editor, the current editor has been very perfect, and in two development has added a lot of new features, simple and easy-to-use, perfect support for multiple conditions complex task htaccess file Intelligent Generation task.

We will also introduce the usage and precautions of this htaccess online generator.

1, open the image of the Web site anti-theft chain function

If the site's traffic is limited, then the picture anti-theft chain is very necessary. Not only can reduce the flow of waste, but also can reduce the burden on the server. Open the image anti-theft chain features need to add the following code to the htaccess file:

Rewriteengine on
Rewritecond%{http_referer}!^$
Rewritecond%{http_referer}!^http://(www\.)? Allow1.com (/)? *$ [NC]
Rewritecond%{http_referer}!^http://(www\.)? Allow2.com (/)? *$ [NC]
Rewriterule *\. (gif|jpg|jpeg|bmp|png) $ http://img.baidu.com/.gif [r,nc,l]

In the above code, allow1.com and allow2.com are the domain names that allow access to the images of the site, followed by the baidu.com of the destination picture address. It also contains the suffix parameter of the picture file, which can be changed by itself. If you generate this code through the Htaccess online generator, just fill out several domain names that are allowed to access (without WWW and HTTP), and then fill in the image address that you want to replace.

2, custom 404, 500 error return page

If you do not want the site to be unable to find the page when the "404 page Cannot Be displayed," Try to define a page you can not find the error page! Need to include in the htaccess file

ErrorDocument 404/404.htm

The previous 404 is its error code, followed by the/404.htm is its own definition of the 404 page path. Note that if this 404 page size is less than 512B, IE will ignore this page, it will not be effective. The following parameters need to use the site relative path. In the htaccess online generator, switch to the custom Error Pages tab and enter your error page address in the input box after 404 (not found). The online build tool can also handle other types of errors, and so on. Please make a 404 error page in advance to upload to the website directory.

3, the first is to screen the list of Web sites

A directory listing is a contingency measure when a Web site cannot find a default file, and the server returns all files in the current directory without reservation. This will bring a very big security risk to the website. As a result, many programs now place a index.htm file under any subdirectory to avoid this omission. However, through the htaccess file we can completely solve this problem.

Add the following code to the file:

Options-indexes

This will completely shut down the site's directory listing feature, but it has no effect on the normal access to the site. If you want to display a list of files, you only need to change "-" to "+". If you are using the htaccess online generation tool, you can simply select "Hide" from the "list of directories that have no default documents" menu and the program will automatically generate the relevant code.

4, the most complex WWW unified Web site format and redirect

In the view of SEO, if ***.com and www.***.com can access, this is a very bad experience for search engines, but also easy to cause weight dispersion. What we need to do is to unify the Web site with www.

We do not recommend manual writing of this code, the automatic generation program has made a perfect judgment, you only need to switch to the "WWW Domain name redirection" tab, in the WWW domain name redirect after the address bar to fill in the name you want to use the final domain! Note that the domain name you fill out here must be a complete URL, such as http:// Www.xxxx.org or http://xxxx.org. The program will automatically determine whether to use positive redirection or reverse redirection based on your input.

5, the default document is annoyed, but also have to do a jump page

Some virtual hosts are alternative, do not apply the default file name, or the order of Non-mainstream. Then you can define the file name of the page by using the following code. such as index.htm, default.php and so on:

DirectoryIndex index.php

This line of code will index.php as the default home page. Other pages please replace the index.php in the example directly. If a site has multiple pages that need to be used as a home page, please write the file in DirectoryIndex index.php index2.php format. This set in the htaccess generator, only need you to fill in the first page of the file name, very convenient.

6, through the htaccess to open the website image cache

Some virtual hosts limit the flow of web sites, and if the browser downloads the most commonly used picture files from the server every time, it will waste a lot of bandwidth. Therefore, you can turn on the image cache, and the browser will automatically load the picture file from the cache before it expires. This feature adds the following code to the file:

<filesmatch ". (Gif|jpg|jpeg|png|ico) $ >
Header set Cache-control "Max-age=3600″
</FilesMatch>

Note that the above 3600 units for seconds, that is, the timeout, GIF in the figure above is a picture file suffix, indicating that these files are in effect. If you use the automatic generation tool, to turn this option on, select a timeout time for the open site Picture Cache tab. There are currently 10 minutes, an hour, a day, and other options available for setup.

7, fixed 301, 302 Web page redirection

Because the 404 error caused by the page transfer location is a big headache for all of us, we just need to do a 301 redirect to completely solve the problem. Add the following code to the htaccess file:

Redirect permanent/old.htm http://www.***.com/new.htm

The previous argument uses a relative path, or it can use a directory name, and the last parameter must complete the URL. This will take effect without error. In SEO, search engines will soon follow your settings, will be included in the Web page update.

In addition, htaccess can also be implemented such as MIME file type modification, domain redirection and other functions, so the full use of the file will make your website more handy.

Finally, we recommend a htaccess online generation editor: http://www.wangqu.org/htaccess/, it is worth collecting into the computer for a rainy.

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.