Table of Contents
You do not have permission to access this page , please give up!
Home Backend Development PHP Tutorial How to write the function of .htaccess file in apache_PHP tutorial

How to write the function of .htaccess file in apache_PHP tutorial

Jul 13, 2016 pm 05:26 PM
apache Writing method Function document of

The functional writing method of .htaccess file in apache - .htaccess file (or "distributed configuration file" provides a method to change the configuration for a directory, that is, placing a file containing one or more instructions in a specific document directory to Applies to this directory and all its subdirectories. As a user, the commands you can use are restricted. Administrators can set it through the Apache AllowOverride directive. Directives in subdirectories will override higher-level directories or main server configurations. directives in the file.
- .htaccess must be uploaded in ASCII mode, preferably with its permissions set to 644.
Location of the error document
Common client request error return codes:
401 Authorization Required
403 Forbidden
404 Not Found
405 Method Not Allowed
408 Request Timed Out
411 Content Length Required
412 Precondition Failed
413 Request Entity Too Long
414 Request URI Too Long
415 Unsupported Media Type
Common server error return codes:
500 Internal Server Error
Users can use .htaccess to specify their own pre-made error reminder page. , people can set up a special directory, such as errors, to place these pages. Then add the following instructions to .htaccess:
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/internalerror.html
One command per line. The first command above means that when the required document is not found, the page must be displayed as the notfound.html page in the /errors directory. It is not difficult to see that the syntax format is:
ErrorDocument. Error code/directory name/file name.extension

If there is very little information to be prompted, there is no need to create a special page and use the HTML number directly in the command, such as the following example:
ErrorDocument 401 "

You do not have permission to access this page , please give up!

"
Password protection for document access
To use .htaccess to set access users and corresponding passwords for documents in a certain directory, the first thing to do is to generate a. The text document of htpasswd, for example:
zheng:y4E7Ep8e7EYV
The password here is encrypted. Users can find some tools to encrypt the password into the encoding supported by .htaccess. It is best not to place this document in the www directory. It is recommended to place it outside the www root directory document, which is safer.
With the authorized user document, you can add the following instructions to .htaccess:
AuthUserFile .htpasswd server directory
AuthGroupFile /dev/null (directory that requires authorized access)
AuthName EnterPassword
AuthType Basic (authorization type)
require user wsabstract (users allowed to access, if you want all users in the table to be allowed, you can use require valid-user)
Note, the brackets are comments added by yourself during learning
Deny access from a certain IP
If I don’t want a certain government department to access the content of my site, I can exclude them by adding the department’s IP in .htaccess.
For example:

order allow,deny
deny from 210.21.112.43
deny from 219.146.95
allow from all
The second line denies an IP, the third OK to deny a certain IP range, that is, 219.146.95.0~219.146.95.255
Want to deny everyone? Just use deny from all. Not only IP, but also domain name can be used to set it.
Protect .htaccess document
When using .htaccess to password-protect a directory, it contains the path to the password file. For security reasons, it is necessary to protect .htaccess so that others cannot see its contents. Although this can be done in other ways, such as permissions on the document. However, .htaccess itself can also do it, just add the following instructions:

order allow,deny
deny from all

URL redirection
We may redesign the website, move documents, or change the directory. At this time, visits from search engines or links from other websites may go wrong. In this case, you can use the following command to automatically redirect the old URL to the new address:
Redirect /old directory/old document name address of the new document
or redirect the entire directory:
Redirect old Directory New Directory
Change the default homepage file
Generally, the default homepage file names include default, index, etc. However, sometimes there is no default file in the directory, but a specific file name, such as pmwiki.php in pmwiki. In this case, it is troublesome for the user to remember the file name to access it. You can easily set a new default file name in .htaccess:
DirectoryIndex You can also list multiple new default file names
, and the order indicates the priority between them, for example:
DirectoryIndex filename.html index.cgi index.pl default.htm

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531994.htmlTechArticleThe function writing method of .htaccess file in apache - .htaccess file (or "distributed configuration file" provides directory-specific To change the configuration, that is, place a...
in a specific document directory
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Application of algorithms in the construction of 58 portrait platform Application of algorithms in the construction of 58 portrait platform May 09, 2024 am 09:01 AM

1. Background of the Construction of 58 Portraits Platform First of all, I would like to share with you the background of the construction of the 58 Portrait Platform. 1. The traditional thinking of the traditional profiling platform is no longer enough. Building a user profiling platform relies on data warehouse modeling capabilities to integrate data from multiple business lines to build accurate user portraits; it also requires data mining to understand user behavior, interests and needs, and provide algorithms. side capabilities; finally, it also needs to have data platform capabilities to efficiently store, query and share user profile data and provide profile services. The main difference between a self-built business profiling platform and a middle-office profiling platform is that the self-built profiling platform serves a single business line and can be customized on demand; the mid-office platform serves multiple business lines, has complex modeling, and provides more general capabilities. 2.58 User portraits of the background of Zhongtai portrait construction

How to conduct concurrency testing and debugging in Java concurrent programming? How to conduct concurrency testing and debugging in Java concurrent programming? May 09, 2024 am 09:33 AM

Concurrency testing and debugging Concurrency testing and debugging in Java concurrent programming are crucial and the following techniques are available: Concurrency testing: Unit testing: Isolate and test a single concurrent task. Integration testing: testing the interaction between multiple concurrent tasks. Load testing: Evaluate an application's performance and scalability under heavy load. Concurrency Debugging: Breakpoints: Pause thread execution and inspect variables or execute code. Logging: Record thread events and status. Stack trace: Identify the source of the exception. Visualization tools: Monitor thread activity and resource usage.

How to add a server in eclipse How to add a server in eclipse May 05, 2024 pm 07:27 PM

To add a server to Eclipse, follow these steps: Create a server runtime environment Configure the server Create a server instance Select the server runtime environment Configure the server instance Start the server deployment project

What is GateToken(GT) currency? Introduction to GT coin functions and token economics What is GateToken(GT) currency? Introduction to GT coin functions and token economics Jul 15, 2024 pm 04:36 PM

What is GateToken(GT) currency? GT (GateToken) is the native asset on the GateChain chain and the official platform currency of Gate.io. The value of GT coins is closely related to the development of Gate.io and GateChain ecology. What is GateChain? GateChain was born in 2018 and is a new generation of high-performance public chain launched by Gate.io. GateChain focuses on protecting the security of users' on-chain assets and providing convenient decentralized transaction services. GateChain's goal is to build an enterprise-level secure and efficient decentralized digital asset storage, distribution and transaction ecosystem. Gatechain has original

How to deploy and maintain a website using PHP How to deploy and maintain a website using PHP May 03, 2024 am 08:54 AM

To successfully deploy and maintain a PHP website, you need to perform the following steps: Select a web server (such as Apache or Nginx) Install PHP Create a database and connect PHP Upload code to the server Set up domain name and DNS Monitoring website maintenance steps include updating PHP and web servers, and backing up the website , monitor error logs and update content.

How to leverage Kubernetes Operator simplifiy PHP cloud deployment? How to leverage Kubernetes Operator simplifiy PHP cloud deployment? May 06, 2024 pm 04:51 PM

KubernetesOperator simplifies PHP cloud deployment by following these steps: Install PHPOperator to interact with the Kubernetes cluster. Deploy the PHP application, declare the image and port. Manage the application using commands such as getting, describing, and viewing logs.

How to implement PHP security best practices How to implement PHP security best practices May 05, 2024 am 10:51 AM

How to Implement PHP Security Best Practices PHP is one of the most popular backend web programming languages ​​used for creating dynamic and interactive websites. However, PHP code can be vulnerable to various security vulnerabilities. Implementing security best practices is critical to protecting your web applications from these threats. Input validation Input validation is a critical first step in validating user input and preventing malicious input such as SQL injection. PHP provides a variety of input validation functions, such as filter_var() and preg_match(). Example: $username=filter_var($_POST['username'],FILTER_SANIT

Java Data Structures and Algorithms: A Practical Guide to Cloud Computing Java Data Structures and Algorithms: A Practical Guide to Cloud Computing May 09, 2024 am 08:12 AM

The use of data structures and algorithms is crucial in cloud computing for managing and processing massive amounts of data. Common data structures include arrays, lists, hash tables, trees, and graphs. Commonly used algorithms include sorting algorithms, search algorithms and graph algorithms. Leveraging the power of Java, developers can use Java collections, thread-safe data structures, and Apache Commons Collections to implement these data structures and algorithms.

See all articles