Five optimization errors that are most likely to occur with a novice using htaccess files

Source: Internet
Author: User
Keywords This can WWW function

Since I have been studying the Official Handbook of Http://www.aliyun.com/zixun/aggregation/14417.html ">apache", I have been 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.

As an overview, the htaccess file is a configuration file in the Apache server that is responsible for the page configuration in the related directory. Through the htaccess file, you can help us achieve: Web 301 redirect, custom 404 error page, change file extension, allow/block specific user or directory access, prohibit directory list, configure default document and other features.

Unix, Linux, or any version of the Apache Web server are supported. htaccess, but some hosting providers may not allow you to customize your own. htaccess files. Most of the domestic virtual host does not have this function. What I know to offer this feature is the Sing Century (the Discuz forum service provider).

Enable. htaccess, you need to modify httpd.conf, enable allowoverride, and you can use allowoverride to limit the use of specific commands. If you need to use a filename other than. htaccess, you can change it using the accessfilename directive. For example, if you need to use. config, you can configure it in the server configuration file in the following ways: Accessfilename. config.

Generally speaking,. Htaccess can help us implement including: folder password protection, user automatic redirection, custom error page, change your file name extension, block specific IP address users, only allow specific IP address of users, prohibit directory list, and use other files as index files, and some other features.

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.

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.