Summary of rookie easy to make htaccess file five optimization errors

Source: Internet
Author: User

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

Since I've been studying Apache's Official Handbook Lately, I'm interested in this powerful and flexible configuration file. htaccess. At the same time, I also have a lot of friends to ask me. htaccess documents related to difficult diseases, here, I have an exclusive summary. htaccess the common writing error of this file, I also hope that friends can learn the lesson and reach a higher level.

1. The. htaccess file is an Apache configuration file, so it is directly determined that the Web site that the file was built with IIS is not valid.

In the official note,. htaccess is a distributed configuration file for a Web site, which, as its name suggests, can be distributed under different directories, each of which has a different scope. For example, put the file in the "admin" directory, then this configuration file only for admin and its subdirectories under the effect of the file.

However, many of the first-entry friends do not know how to handle this configuration file. Here's what I'm telling you, if you want the entire site to be in effect, build this file in the root directory of your site.

2, this file is very easy to cause server 500 error, and most of the reason is the Windows file encoding error.

Because the file is a native Linux file, it cannot be created under Windows by using a Notepad program that is brought in from the system. However, you can change the code to remove unnecessary content such as BOM. However, we strongly recommend using Rich text editors such as Notepad2 to create this file and save it as an international encoding format such as UTF-8. Of course, you can also use some online htaccess editor to automatically create this file, the article will be related to the introduction.

3. htaccess file Set Picture anti-theft chain, the replacement of the target picture must not be the current domain picture file. Failure to do so will result in a loop error.

Many friends will use the. htaccess file to achieve the effect of the picture anti-theft chain, reduce space due to picture hotlinking waste of traffic. However, it ignores this: you cannot place the replaced target picture in this field. The reason is as follows: This domain uses the picture anti-theft chain function, therefore, all access to the domain's picture address through other domains will be rewritten as the destination address, but if the destination address is also the picture in this domain, can cause the circular error, may even cause the client browser to suspend animation.

4, the WWW domain name unified jump instruction security writing.

Many friends will pass the. htaccess file to unify the domain name with www and the domain name without www, then write a similar statement like the following:

Rewritecond%{http_host}!^www.domain.com? [NC]

Note that this is a very unsafe and irresponsible way of writing, because the use of the "!" (non). This type of writing will be the htaccess of all the scope of the URL to jump, such as will be "m.domain.com" jump into the "www.domain.com", will be "bbs.domain.com also jump to" www.domain.com. It is conceivable that it may cause problems. Therefore, the correct and safe formulation of the directive should be:

Rewritecond%{http_host} ^ (domain\.com) (: 80)? [NC]

This avoids interfering with other subdomains, and also avoids the jump of other ports on the host. This is a very strict and safe way of writing.

5, whether to open the file list display instructions:

Options-indexes or Options +indexes

Indexes must add "+" or "-" before it overrides other important settings defined by the host ancestor configuration file. The "Htaccesseditor" editor, which is widely circulated on the internet, is wrong. As a result, many friends found that the use of this feature after the site can not browse. The reason is this:

The parameters after the options are all written on: Options (+-) execcgi (+-) followsymlinks (+-) recursively (+-) Indexes ... If you do not add "+" or "-" to the front of the argument, the directive defaults to open except for this parameter, and all other parameters are turned off, similar to the chmod command under Linux. This causes the execcgi to also shut down, which will cause all pages to be unable to execute the script.

These common errors mentioned above are discovered when I write "htaccess file Online Editor", and many of them are the suggestions that netizens give me, I thank you here!

At the same time, I have attached a few very useful htaccess online editor for your favorite use:

1. htaccess generator:http://developers.evrsoft.com/tools-htaccess-generator.shtml

This editor features a convenient definition of the picture anti-theft chain, 404 error page address and picture cache control and password protection, but the English page, and a single function, can not be flexible settings.

2. htaccess file generator:http://cooletips.de/htaccess/

This editor is powerful and the originator of an online editor. But the page clutter, semantic ambiguity, without any explanation, very easy to fill in the wrong. But its powerful function is still the masters of the choice.

3, Htaccess Disable hotlinking Code generator:http://www.htmlbasix.com/disablehotlinking.shtml

This is specifically used to generate a picture anti-theft chain tool, therefore, it also has a unique picture anti-theft chain function, but do very meticulous, but also very flexible. Can define the picture file type, the target picture's address and so on detailed parameter.

4. htaccess file Online generator: http://www.wangqu.org/htaccess/

Objectively speaking, this is one of the most fully functional and humanized online editors in many generators. Chinese interface, including pictures anti-theft chain, MIME type Add, access control, custom default page, custom various error documents, Web page redirection, picture caching and other nine functions, each feature has been carefully debugged, and have detailed examples and functional description for reference. It also has the ability to download the generated. htaccess files, avoiding the various errors created by your own files.

summed up these. htaccess file in the process of writing error prone, just hope that friends of the website can better build their own web site, and finally, I wish you more and more friends website visit!

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.