Apache Tutorial:. htaccess usage

Source: Internet
Author: User
Tags error code

Apache Tutorial:. htaccess usage

Really cool feature, Web designers ignore is used. Htaccess file. In short, when you see a custom error page (404,403, etc.), use the server to include, restrict IP addresses, load the hosts page, or do any host event invisible to users, you may use it. Htaccess.

This document describes how to create a redViper in the add custom error page tutorial. I will provide examples of further projects that you can add. The htaccess file is not just a custom error page.

. Htaccess is a simple text file that you add and edit in a text editor such as Notepad. You save the file. Htaccess does not have any additional characters before or after the file name. I know what is strange about the file name. Besides, the coolest thing. The following describes how to upload files to the network server:

In any case, the following sections will try to highlight some of the more useful ones. The features and codes of htaccess require the work of these functions. To test the following functions, copy and paste the code of line (s), go to notepad, and save the file. And upload the file to the Web server in the root directory of the website.

Here:

Custom error page
Don't you hate it when people access your website through a bad link and are facing an error message, such as "license denied" or "no web page found "? Then, you can create custom error pages for busy error messages. For each type of error, it is expected that your visit will encounter:

ErrorDocument 404 Http:// Www.111cn.net/404.htm
ErrorDocument 401 /Admin/Authorization.Htm
ErrorDocument 403 /Password/Forbidden.Htm

To create a custom error page, add ErrorDocument next to the error code to the appropriate error code, and change the webpage of the website to receive error-prone users! For example, the following is the 404 error page for this website: http://www.111cn.net/404.htm

Redirection
This is a nightmare. You decide to put the page and image of the value of the entire folder into a new folder on your server. If you do not use any third-party programs to update any links to new locations, your users will see many custom error pages that you may have used.
 
One solution would be yes. The redirection function of the htaccess file. For example, if you are interested in redirecting the so-called temperature from the folder to another folder, you can use the following code:

The Redirect/temp http://www.kirupa.com/developer

If the first parameter is a folder or file name, you are trying to rename it, and in the second parameter is a file or directory, you are trying to make people replace it:

RedirectOld file/folderNew file/folder

The above line of code is a template, how to redirect the function. Htaccess project.

Change homepage/directory page
When a local network is connected to your website, The index.htm or similar webpage will be the first in load. You can actually use it. When htaccess and changed files are loaded, you first get your website load

DirectoryIndex File.htm

In the authorization code, obtain the new authorization page with the file.htm name. Refer in the above code.

:.HtaccessIP interception
If you want to prevent an individual or a group of individuals from accessing your website within a certain IP address range, you can choose not to contact them.
 
You can use the following command format

<Limit get head post>
Order allow, deny
Deny from 18.52.3.5
Deny from 18.132.152
Deny from 24.2
Allow from all
</LIMIT>

Of course, you may not be interested in blocking fictitious IP addresses as described above. You should change those things to make more sense. If you really don't like it, you can add a lot of code that denies the line from what you want.

If someone is listening from the entire IP address range, it can block all IP addresses in the range and only enter a small part of its own IP address, such as 24.2. All IP addresses, such as 24.2.35.3 and 24.2.142.122, are automatically blocked. You may need to be careful about the websites you may not want to block visitors from accessing.

Application. Htaccess folder and subfolders
Your. The htaccess file does not need to be in the root directory. You can put it in any Directory-then it applies to the directory where you put it, and all subdirectories.

You can also only allow some IP addresses-for example:

Order allow, deny
Allow from 123.456.78920.12
Deny from all
It may not be so useful if you apply to your entire website, but when used well, with other directories.

Above. I think you like htaccess. Remember that some server hosts can be used. Htaccess infringes on your privileges. Some HTML editing programs may have their own file management and access systems. They are present when they are not in good time. Htaccess. In addition, the IIS server does not support this function. Htaccess.

Because njs12345 provides some additional features. Htaccess insights on sub-folders/folders and IIS servers.

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.