Hướng dẫn add php handler htaccess - thêm htaccess trình xử lý php

htaccess is a very ancient configuration file that controls the Web Server running your website, and is one of the most powerful configuration files you will ever come across. .htaccess has the ability to control access/settings for the HyperText Transfer Protocol (HTTP) using Password Protection, 301 Redirects, rewrites, and much much more. This is because this configuration file was coded in the earliest days of the web (HTTP), for one of the first Web Servers ever! Eventually these Web Servers (configured with htaccess) became known as the World Wide Web, and eventually grew into the Internet we use today.

Hướng dẫn add php handler htaccess - thêm htaccess trình xử lý php
This is not an introduction to htaccess. This is a guide for using htaccess to the fullest. Originally (2003) this guide was known in certain hacker circles and hidden corners of the net as an ultimate htaccess due to the powerful htaccess tricks and tips to bypass security on a webhost, and also because many of the htaccess examples were pretty impressive back then in that group.

Show

Table of Contents

  1. Introduction
    1. Htaccess - Evolved
    2. AskApache Htaccess Journey
    3. What Is .htaccess
      1. Creating Htaccess Files
      2. Htaccess Scope
    4. Htaccess File Syntax
    5. Htaccess Directives
    6. Main Server Config Examples
    7. Example .htaccess Code Snippets
      1. Redirect Everyone Except IP address to alternate page
      2. When developing sites
      3. Fix double-login prompt
      4. Set Timezone of the Server (GMT)
      5. Administrator Email for ErrorDocument
      6. Options -ExecCGI
        AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
        
        1 for
        Options -ExecCGI
        AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
        
        2
      7. Charset and Language headers
      8. Disallow Script Execution
      9. Deny Request Methods
      10. Force "File Save As" Prompt
      11. Show CGI Source Code
      12. Serve all .pdf files on your site using .htaccess and mod_rewrite with the php script.
      13. Rewrite to www
      14. Rewrite to www dynamically
      15. 301 Redirect Old File
      16. 301 Redirect Entire Directory
      17. Protecting your php.cgi
      18. Set Cookie based on Request
      19. Set Cookie with env variable
      20. Custom ErrorDocuments
      21. Implementing a Caching Scheme with .htaccess
      22. Password Protect single file
      23. Password Protect multiple files
      24. Send Custom Headers
      25. Blocking based on User-Agent Header
      26. Blocking with RewriteCond
      27. .htaccess for mod_php
      28. .htaccess for php as cgi
      29. Shell wrapper for custom php.ini
      30. Add values from HTTP Headers
      31. Stop hotlinking
    8. Example .htaccess Files
    9. Advanced Mod_Rewrites
      1. Directory Protection
      2. Password Protect wp-login.php
      3. Password Protect wp-admin
      4. Protect wp-content
      5. Protect wp-includes
      6. Common Exploits
      7. Stop Hotlinking
      8. Safe Request Methods
      9. Forbid Proxies
      10. Real wp-comments-post.php
      11. HTTP PROTOCOL
      12. SPECIFY CHARACTERS
      13. BAD Content Length
      14. BAD Content Type
      15. Missing HTTP_HOST
      16. Bogus Graphics Exploit
      17. No UserAgent, Not POST
      18. No Referer, No Comment
      19. Trackback Spam
      20. Map all URIs except those corresponding to existing files to a handler
      21. Map any request to a handler
      22. And for CGI scripts:
      23. Map URIs corresponding to existing files to a handler instead
      24. Deny access if var=val contains the string foo.
      25. Removing the Query String
      26. Adding to the Query String
      27. Rewriting For Certain Query Strings
      28. Modifying the Query String
    10. Best .htaccess Articles
      1. .htaccess for Webmasters
      2. Mod_Rewrite URL Rewriting
      3. 301 Redirects without mod_rewrite
      4. Secure PHP with .htaccess
      5. .htaccess Cookie Manipulation
      6. .htaccess Caching
      7. Password Protection and Authentication
      8. Control HTTP Headers
      9. Blocking Spam and bad Bots
      10. PHP htaccess tips
      11. HTTP to HTTPS Redirects with mod_rewrite
      12. SSL in .htaccess
      13. SetEnvIf and SetEnvIfNoCase in .htaccess
      14. Site Security with .htaccess
      15. Merging Notes
    11. My Favorite .htaccess Links
    12. Htaccess Directives
    13. Htaccess Variables
    14. Htaccess Modules
    15. Htaccess Software
    16. Technical Look at .htaccess
      1. Per-directory configuration structures
      2. Command handling
        1. mod_autoindex
        2. mod_rewrite
      3. Side notes --- per-server configuration, virtual servers, etc.
      4. Litespeed Htaccess support

Htaccess - Evolved

The Hyper Text Transfer Protocol (HTTP) was initiated at the CERN in Geneve (Switzerland), where it emerged (together with the HTML presentation language) from the need to exchange scientific information on a computer network in a simple manner. The first public HTTP implementation only allowed for plain text information, and almost instantaneously became a replacement of the GOPHER service. One of the first text-based browsers was LYNX which still exists today; a graphical HTTP client appeared very quickly with the name NCSA Mosaic. Mosaic was a popular browser back in 1994. Soon the need for a more rich multimedia experience was born, and the markup language provided support for a growing multitude of media types.

AskApache Htaccess Journey

Skip this - still under edit I discovered these tips and tricks mostly while working as a network security penetration specialist hired to find security holes in web hosting environments. Shared hosting is the most common and cheapest form of web-hosting where multiple customers are placed on a single machine and "share" the resources (CPU/RAM/SPACE). The machines are configured to basically ONLY do HTTP and FTP. No shells or any interactive logins, no ssh, just FTP access. That is when I started examining htaccess files in great detail and learned about the incredible untapped power of htaccess. For 99% of the worlds best Apache admins, they don't use .htaccess much, if AT ALL. It's much easier, safer, and faster to configure Apache using the httpd.conf file instead. However, this file is almost never readable on shared-hosts, and I've never seen it writable. So the only avenue left for those on shared-hosting was and is the .htaccess file, and holy freaking fiber-optics.. it's almost as powerful as httpd.conf itself! Most all .htaccess code works in the httpd.conf file, but not all httpd.conf code works in .htaccess files, around 50%. So all the best Apache admins and programmers never used .htaccess files. There was no incentive for those with access to httpd.conf to use htaccess, and the gap grew. It's common to see "computer gurus" on forums and mailing lists rail against all uses and users of .htaccess files, smugly announcing the well known problems with .htaccess files compared with httpd.conf - I wonder if these "gurus" know the history of the htaccess file, like it's use in the earliest versions of the HTTP Server- NCSA's HTTPd, which BTW, became known as Apache HTTP. So you could easily say that htaccess files predates Apache itself. Once I discovered what .htaccess files could do towards helping me enumerate and exploit security vulnerabilities even on big shared-hosts I focused all my research into .htaccess files, meaning I was reading the venerable Apache HTTP Source code 24/7! I compiled every released version of the Apache Web Server, ever, even NCSA's, and focused on enumerating the most powerful htaccess directives. Good times! Because my focus was on protocol/file/network vulnerabilites instead of web dev I built up a nice toolbox of htaccess tricks to do unusual things. When I switched over to webdev in 2005 I started using htaccess for websites, not research. I documented most of my favorites and rewrote the htaccess guide for webdevelopers. After some great encouragement on various forums and nets I decided to start a blog to share my work with everyone, AskApache.com was registered, I published my guide, and it was quickly plagiarized and scraped all over the net. Information is freedom, and freedom is information, so this blog has the least restrictive copyright for you. Feel free to modify, copy, republish, sell, or use anything on this site ;)

.Htaccess là gì

Cụ thể, .htaccess là tên tệp mặc định của tệp cấu hình đặc biệt cung cấp một số chỉ thị (lệnh) để kiểm soát và định cấu hình máy chủ web Apache, và cũng để điều khiển và định cấu hình các mô -đun có thể được tích hợp vào cài đặt Apache hoặc bao gồm Tại thời gian chạy như mod_rewrite (để viết lại htaccess), mod_alias (đối với chuyển hướng htaccess) và mod_ssl (để kiểm soát các kết nối SSL). HTACCESS cho phép quản lý các cấu hình máy chủ web phi tập trung, điều này làm cho cuộc sống rất dễ dàng đối với các công ty lưu trữ web và đặc biệt là người tiêu dùng hiểu biết của họ. Họ đã thiết lập và chạy "trang trại máy chủ" trong đó hàng trăm và hàng ngàn khách hàng lưu trữ web đều được đặt trên cùng một máy chủ Apache. Loại lưu trữ này được gọi là "lưu trữ ảo" và không có tệp .htaccess có nghĩa là mọi khách hàng phải sử dụng các cài đặt chính xác giống như mọi người khác trên phân khúc của họ. Vì vậy, đó là lý do tại sao bất kỳ máy chủ web nửa decent nào cho phép/cho phép (Dreamhost, Powweb, Mediatemple, GoDaddy) .htaccess, mặc dù ít người biết về nó. Chúng ta hãy nói rằng nếu tôi là khách hàng trên máy chủ của bạn và các tệp .htaccess được bật, các trang web của tôi sẽ nhanh hơn rất nhiều so với của bạn, vì các tệp cấu hình này cho phép bạn tận dụng hoàn toàn và sử dụng các tài nguyên được phân bổ cho bạn bởi chủ nhà của bạn. Nếu thậm chí 1/10 trang web trên trang trại máy chủ đã tận dụng những gì họ đang trả tiền, các nhà cung cấp sẽ ngừng hoạt động.Htaccess allows for decentralized management of Web Server configurations which makes life very easy for web hosting companies and especially their savvy consumers. They set up and run "server farms" where many hundreds and thousands of web hosting customers are all put on the same Apache Server. This type of hosting is called "virtual hosting" and without .htaccess files would mean that every customer must use the same exact settings as everyone else on their segment. So that is why any half-decent web host allows/enables (DreamHost, Powweb, MediaTemple, GoDaddy) .htaccess files, though few people are aware of it. Let's just say that if I was a customer on your server-farm, and .htaccess files were enabled, my websites would be a LOT faster than yours, as these configuration files allow you to fully take advantage of and utilize the resources allotted to you by your host. If even 1/10 of the sites on a server-farm took advantage of what they are paying for, the providers would go out of business.

Bỏ qua: Lịch sử của HTAccess trong Apache 1st. Một trong các mục tiêu thiết kế cho máy chủ này là duy trì khả năng tương thích bên ngoài với máy chủ NCSA 1.3 --- nghĩa là đọc cùng một tệp cấu hình, để xử lý tất cả các chỉ thị trong đó và nói chung là thay thế NCSA. Mặt khác, một mục tiêu thiết kế khác là di chuyển càng nhiều chức năng của máy chủ thành các mô -đun có ít nhất có thể với lõi máy chủ nguyên khối. Cách duy nhất để điều hòa các mục tiêu này là chuyển cách xử lý của hầu hết các lệnh từ máy chủ trung tâm vào các mô -đun. Tuy nhiên, chỉ cần đưa ra các bảng lệnh mô -đun là không đủ để ly dị chúng hoàn toàn khỏi lõi máy chủ. Máy chủ phải nhớ các lệnh để hành động theo chúng sau. Điều đó liên quan đến việc duy trì dữ liệu riêng tư cho các mô-đun và có thể là máy chủ trên mỗi người, hoặc mỗi phương pháp. Hầu hết mọi thứ là mỗi phương pháp, bao gồm thông tin ủy quyền và kiểm soát truy cập cụ thể, nhưng cũng thông tin về cách xác định các loại tệp từ các hậu tố, có thể được sửa đổi bằng các chỉ thị AddType và DefaultType, v.v. Nói chung, triết lý quản lý là bất cứ điều gì có thể được thực hiện bằng thư mục phải được cấu hình; Thông tin trên mỗi máy chủ thường được sử dụng trong bộ mô-đun tiêu chuẩn cho thông tin như bí danh và chuyển hướng đi vào hoạt động trước khi yêu cầu gắn liền với một vị trí cụ thể trong hệ thống tệp bên dưới. Một yêu cầu khác để mô phỏng máy chủ NCSA là có thể xử lý các tệp cấu hình mỗi phương thức, thường được gọi là các tệp .htaccess, mặc dù trong máy chủ NCSA, chúng có thể chứa các chỉ thị không liên quan gì đến điều khiển truy cập. Theo đó, sau khi dịch URI -> FileName, nhưng trước khi thực hiện bất kỳ pha nào khác, máy chủ sẽ giảm hệ thống phân cấp thư mục của hệ thống tệp cơ bản, theo tên đường dẫn được dịch, để đọc bất kỳ tệp .htaccess nào có thể có. Thông tin được đọc trong đó phải được hợp nhất với thông tin áp dụng từ các tệp cấu hình của máy chủ (từ các phần
Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
3 trong access.conf hoặc từ mặc định trong srm.conf, thực sự hoạt động cho hầu hết các mục đích gần như chính xác như
Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
3 ). Cuối cùng, sau khi phục vụ một yêu cầu liên quan đến việc đọc các tệp .htaccess, chúng ta cần loại bỏ bộ lưu trữ được phân bổ để xử lý chúng. Điều đó đã được giải quyết giống như cách nó được giải quyết bất cứ nơi nào khác các vấn đề tương tự xuất hiện, bằng cách buộc các cấu trúc đó vào nhóm tài nguyên giao dịch.
History of Htaccess in 1st Apache. One of the design goals for this server was to maintain external compatibility with the NCSA 1.3 server --- that is, to read the same configuration files, to process all the directives therein correctly, and in general to be a drop-in replacement for NCSA. On the other hand, another design goal was to move as much of the server's functionality into modules which have as little as possible to do with the monolithic server core. The only way to reconcile these goals is to move the handling of most commands from the central server into the modules. However, just giving the modules command tables is not enough to divorce them completely from the server core. The server has to remember the commands in order to act on them later. That involves maintaining data which is private to the modules, and which can be either per-server, or per-directory. Most things are per-directory, including in particular access control and authorization information, but also information on how to determine file types from suffixes, which can be modified by AddType and DefaultType directives, and so forth. In general, the governing philosophy is that anything which can be made configurable by directory should be; per-server information is generally used in the standard set of modules for information like Aliases and Redirects which come into play before the request is tied to a particular place in the underlying file system. Another requirement for emulating the NCSA server is being able to handle the per-directory configuration files, generally called .htaccess files, though even in the NCSA server they can contain directives which have nothing at all to do with access control. Accordingly, after URI -> filename translation, but before performing any other phase, the server walks down the directory hierarchy of the underlying filesystem, following the translated pathname, to read any .htaccess files which might be present. The information which is read in then has to be merged with the applicable information from the server's own config files (either from the
Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
3 sections in access.conf, or from defaults in srm.conf, which actually behaves for most purposes almost exactly like
Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
3). Finally, after having served a request which involved reading .htaccess files, we need to discard the storage allocated for handling them. That is solved the same way it is solved wherever else similar problems come up, by tying those structures to the per-transaction resource pool.

Tạo tệp HTACCESS

Các tệp htaccess sử dụng tên tệp mặc định "

Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
5" nhưng bất kỳ tên tệp kiểu UNIX nào cũng có thể được chỉ định từ cấu hình máy chủ chính bằng Chỉ thị
Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
6. Tệp không phải là
Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
7, theo nghĩa đen của nó chỉ được đặt tên là
Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
5.

Phạm vi HTACCESS

Không giống như các tệp cấu hình máy chủ chính như httpd.conf, các tệp htaccess được đọc trên mọi yêu cầu do đó các thay đổi trong các tệp này có hiệu lực ngay lập tức. Apache tìm kiếm tất cả các thư mục và thư mục con được hỗ trợ HTAccess cho tệp .htaccess dẫn đến mất hiệu suất do truy cập tệp. Tôi chưa bao giờ nhận thấy mất hiệu suất nhưng Otoh, tôi biết cách sử dụng chúng. Nếu bạn có quyền truy cập vào tệp cấu hình máy chủ chính của mình, tất nhiên bạn nên sử dụng điều đó và may mắn cho bạn tất cả các thủ thuật và ví dụ .htaccess cũng có thể được sử dụng ở đó (không chỉ là ngược lại).Htaccess files are read on every request therefore changes in these files take immediate effect. Apache searches all directories and subdirectories that are htaccess-enabled for an .htaccess file which results in performance loss due to file accesses. I've never noticed a performance loss but OTOH, I know how to use them. If you do have access to your main server configuration file, you should of course use that instead, and lucky for you ALL the .htaccess tricks and examples can be used there as well (just not vice versa).

HTACCESS FILE Cú pháp

Các tệp htaccess theo cùng một cú pháp với các tệp cấu hình Apache chính, cho các trình tăng cường đây là Apache.vim cho VI. Một sự khác biệt chính là bối cảnh của chỉ thị, có nghĩa là có được chỉ thị đó được phép sử dụng bên trong tệp .htaccess hay không. Các tệp HTAccess cực kỳ mạnh mẽ và cũng có thể rất nguy hiểm vì một số chỉ thị được phép trong các tệp cấu hình chính sẽ cho phép người dùng/khách hàng vượt qua hoàn toàn bảo mật/băng thông/giới hạn tài nguyên/permissions, v.v. của tất cả các chỉ thị của Apache không thể được sử dụng bên trong tệp .htaccess (còn được gọi là cấu hình ngữ cảnh mỗi phương thức). Các nhà phát triển Apache được đánh giá cao trên toàn thế giới là một trong những lập trình viên giỏi nhất, từ trước đến nay. Để cho phép một chỉ thị không được phép bên trong tệp .htaccess sẽ yêu cầu sửa đổi mã nguồn và biên dịch lại máy chủ (mà họ cho phép và khuyến khích nếu bạn là chủ sở hữu/quản trị viên).

Chỉ thị HTACCESS

Đừng hỏi tại sao, nhưng cá nhân tôi đã tải xuống từng bản phát hành chính/beta của mã nguồn httpd apache từ phiên bản 1.3.0 xuống phiên bản 2.2.10 (tất cả 63 phiên bản Apache!), Sau đó tôi đã cấu hình và biên dịch từng phiên bản cho một HTTPD tùy chỉnh Cài đặt được xây dựng từ nguồn. Điều này cho phép tôi tìm thấy mọi chỉ thị được phép trong các tệp .htaccess và mọi biến trong các tệp .htaccess cho mỗi phiên bản cụ thể, chưa từng được thực hiện trước đây hoặc kể từ đó. VÂNG! Tôi nghĩ rằng điều đó thật tuyệt vời .. Chỉ thị .htaccess về cơ bản là một lệnh cụ thể cho một mô -đun hoặc tích hợp vào lõi thực hiện một nhiệm vụ cụ thể hoặc đặt một cài đặt cụ thể cho cách Apache phục vụ trang web của bạn. Các chỉ thị được đặt trong các tệp htaccess áp dụng cho thư mục chúng đang ở và tất cả các thư mục phụ. Dưới đây là 3 liên kết hàng đầu (tài liệu chính thức của Apache) bạn sẽ liên tục sử dụng, đánh dấu/in/lưu chúng., but I personally downloaded each major/beta release of the Apache HTTPD source code from version 1.3.0 to version 2.2.10 (all 63 Apache versions!), then I configured and compiled each version for a custom HTTPD installation built from source. This allowed me to find every directive allowed in .htaccess files and every variable in .htaccess files for each particular version, which has never been done before, or since. YES! I think that is so cool.. An .htaccess directive is basically a command that is specific to a module or builtin to the core that performs a specific task or sets a specific setting for how Apache serves your WebSite. Directives placed in Htaccess files apply to the directory they are in, and all sub-directories. Here's the 3 top links (official Apache Docs) you will repeatedly use, bookmark/print/save them.

Hướng dẫn add php handler htaccess - thêm htaccess trình xử lý php

  1. Các điều khoản được sử dụng để mô tả các chỉ thị
  2. Danh sách chính thức của các chỉ thị Apache
  3. Tham khảo nhanh chỉ thị-với bối cảnh

Ví dụ cấu hình máy chủ chính

Bây giờ chúng ta hãy xem một số ví dụ HTAccess để cảm nhận về cú pháp và một số ý tưởng chung về các khả năng. Một số ví dụ tốt nhất cho các tệp .htaccess được bao gồm với Apache cho các tệp cấu hình máy chủ chính, vì vậy hãy xem nhanh một vài trong số chúng trên đường xuống. Dành thời gian của bạn). Cú pháp cơ bản là một dòng bắt đầu với # là một nhận xét, mọi thứ khác là các chỉ thị theo sau là đối số chỉ thị. HTTPD-Multilang-errordoc.conf: Cấu hình bên dưới thực hiện các tài liệu lỗi đa ngôn ngữ thông qua đàm phán nội dung ở đây là phần còn lại của chúng nếu bạn muốn xem. khônga line starting with # is a comment, everything else are directives followed by the directive argument. httpd-multilang-errordoc.conf: The configuration below implements multi-language error documents through content-negotiation Here are the rest of them if you wanna take a look. (httpd-mpm.conf, httpd-default.conf, httpd-ssl.conf, httpd-info.conf, httpd-vhosts.conf, httpd-dav.conf)


Ví dụ .htaccess CNIPPETS

Dưới đây là một số ví dụ cụ thể, đây là phần phổ biến nhất của trang này. Cập nhật thường xuyên.

Chuyển hướng mọi người trừ địa chỉ IP sang trang thay thế

ErrorDocument 403 https://www.yahoo.com/
Order deny,allow
Deny from all
Allow from 208.113.134.190

Khi phát triển các trang web

Điều này cho phép Google thu thập trang, cho phép tôi truy cập mà không cần mật khẩu và cho phép khách hàng của tôi truy cập trang bằng mật khẩu. Nó cũng cho phép xác thực XHTML và CSS! (W3.org)

AuthName "Under Development"
AuthUserFile /web/sitename.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
Satisfy Any

Khắc phục lời nhắc ký hiệu kép

Chuyển hướng các yêu cầu không phải HTTPS đến máy chủ HTTPS và đảm bảo rằng .htpasswd ủy quyền chỉ có thể được nhập trên HTTPS.htpasswd authorization can only be entered across HTTPS

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com

Đặt múi giờ của máy chủ (GMT)

SetEnv TZ America/Las_Vegas

Quản trị email cho Errordocument

SetEnv SERVER_ADMIN 

Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
1 cho
Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
2

ServerSignature off | on | email

Bài viết: Đặt Charset trong HTACCESS, và bài viết của Richard Ishida

AddDefaultCharset UTF-8
DefaultLanguage en-US

Không cho phép thực thi tập lệnh

Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi

Từ chối các phương thức yêu cầu

RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
RewriteRule .? - [F]

Lực lượng "Save As Prompt

AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4

Hiển thị mã nguồn CGI

AuthName "Under Development"
AuthUserFile /web/sitename.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
Satisfy Any
0

Phục vụ tất cả các tệp .pdf trên trang web của bạn bằng .htaccess và mod_rewrite với tập lệnh PHP.

AuthName "Under Development"
AuthUserFile /web/sitename.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
Satisfy Any
1

Viết lại vào www

AuthName "Under Development"
AuthUserFile /web/sitename.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
Satisfy Any
2

Viết lại để www một cách linh hoạt

AuthName "Under Development"
AuthUserFile /web/sitename.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
Satisfy Any
3

301 chuyển hướng tệp cũ

AuthName "Under Development"
AuthUserFile /web/sitename.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
Satisfy Any
4

301 Chuyển hướng toàn bộ thư mục

AuthName "Under Development"
AuthUserFile /web/sitename.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
Satisfy Any
5

Bảo vệ PHP.CGI của bạn

AuthName "Under Development"
AuthUserFile /web/sitename.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
Satisfy Any
6

Đặt cookie dựa trên yêu cầu

Mã này gửi tiêu đề

RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
RewriteRule .? - [F]
1 để tạo cookie trên máy khách với giá trị của một mục phù hợp trong các parantheses thứ 2.

AuthName "Under Development"
AuthUserFile /web/sitename.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
Satisfy Any
7

Đặt cookie với biến env

AuthName "Under Development"
AuthUserFile /web/sitename.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
Satisfy Any
8

Tùy chỉnh Errordocument

AuthName "Under Development"
AuthUserFile /web/sitename.com/.htpasswd
AuthType basic
Require valid-user
Order deny,allow
Deny from all
Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
Satisfy Any
9

Thực hiện sơ đồ bộ nhớ đệm với .htaccess

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
0

Mật khẩu bảo vệ tệp đơn

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
1

Mật khẩu bảo vệ nhiều tệp

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
2
SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
3
SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
4

Chặn với viết lại

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
5

.htaccess cho mod_php

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
6

.htaccess cho PHP là CGI

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
7

Vỏ bọc cho Php.ini tùy chỉnh

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
8
SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "askapache.com"
ErrorDocument 403 https://askapache.com
9

Ngừng liên kết nóng

SetEnv TZ America/Las_Vegas
0

Ví dụ .htaccess tệp

Dưới đây là một số mẫu và ví dụ được lấy từ các tệp .htaccess khác nhau mà tôi đã sử dụng trong nhiều năm qua. Các giải pháp cụ thể ở xa hơn trên trang này và trên toàn bộ trang web.

SetEnv TZ America/Las_Vegas
1
SetEnv TZ America/Las_Vegas
2

Dưới đây là một số ví dụ mã mod_rewrite mặc định.

SetEnv TZ America/Las_Vegas
3

Ví dụ về việc bảo vệ các tập tin của bạn và đảm bảo bảo vệ mật khẩu.

SetEnv TZ America/Las_Vegas
4

Mod_rewrites nâng cao

Dưới đây là một số ví dụ HTAccess cụ thể được lấy chủ yếu từ plugin bảo vệ mật khẩu WordPress của tôi, rất nhiều so với bảo vệ mật khẩu như bạn sẽ thấy từ các ví dụ mod_rewrite sau đây. Đây là một vài trong số các sử dụng mod_rewrite mà BlogSecurity tuyên bố đã đẩy ranh giới của mod_rewrite! Một số đoạn trích này khá kỳ lạ và không giống như bất cứ điều gì bạn có thể thấy trước đây, cũng chỉ cho những người hiểu chúng vì chúng có thể giết một trang web khá nhanh.pushed the boundaries of Mod_Rewrite! Some of these snippets are quite exotic and unlike anything you may have seen before, also only for those who understand them as they can kill a website pretty quick.

Bảo vệ thư mục

Kích hoạt bảo vệ thư mục, ngăn chặn danh sách chỉ số thư mục và mặc định. [Vô hiệu hóa]

SetEnv TZ America/Las_Vegas
5

Mật khẩu Bảo vệ WP-Login.php

Yêu cầu người dùng/Pass hợp lệ để truy cập trang đăng nhập [401]

SetEnv TZ America/Las_Vegas
6

Mật khẩu Bảo vệ WP-Admin

Yêu cầu người dùng/Pass hợp lệ để truy cập vào bất kỳ tệp không tĩnh (CSS, JS, hình ảnh) nào trong thư mục này. [401]

SetEnv TZ America/Las_Vegas
7

Bảo vệ nội dung WP

Từ chối mọi yêu cầu trực tiếp cho các tệp kết thúc bằng .php với 403 bị cấm .. có thể phá vỡ các plugin/chủ đề [401]

SetEnv TZ America/Las_Vegas
8

Bảo vệ phần mềm WP

Từ chối mọi yêu cầu trực tiếp cho các tệp kết thúc bằng .php với 403 bị cấm .. có thể phá vỡ các plugin/chủ đề [403]

SetEnv TZ America/Las_Vegas
9

Khai thác phổ biến

Chặn các yêu cầu khai thác phổ biến với 403 bị cấm. Những điều này có thể giúp rất nhiều, có thể phá vỡ một số plugin. [403]

SetEnv SERVER_ADMIN 
0

Ngừng liên kết nóng

Từ chối mọi yêu cầu cho các tệp tĩnh (hình ảnh, CSS, v.v.) nếu người giới thiệu không phải là trang web cục bộ hoặc trống. [403]

SetEnv SERVER_ADMIN 
1

Phương pháp yêu cầu an toàn

Từ chối mọi yêu cầu không sử dụng GET, propfind, post, tùy chọn, đặt, đứng đầu [403]

SetEnv SERVER_ADMIN 
2

Cấm proxy

Từ chối mọi yêu cầu bài viết bằng máy chủ proxy. Vẫn có thể truy cập trang web, nhưng không bình luận. Xem báo chí dễ hỏng [403]

SetEnv SERVER_ADMIN 
3

Từ chối bất kỳ nỗ lực đăng nào được thực hiện đối với WP-Comments-Post.php không tồn tại [403]

SetEnv SERVER_ADMIN 
4

Giao thức HTTP

Từ chối bất kỳ giao thức HTTP được hình thành xấu nào trong yêu cầu, 0,9, 1.0 và chỉ 1,1 [403]

SetEnv SERVER_ADMIN 
5

Chỉ định các ký tự

Từ chối bất kỳ yêu cầu nào cho một URL chứa các ký tự khác ngoài "A-A-Z0-9.+/-? = &"-thực sự có ích nhưng có thể phá vỡ trang web của bạn tùy thuộc vào liên kết của bạn. [403]

SetEnv SERVER_ADMIN 
6

Chiều dài nội dung xấu

Từ chối bất kỳ yêu cầu bài đăng nào không có tiêu đề độ dài nội dung [403]

SetEnv SERVER_ADMIN 
7

Loại nội dung xấu

Từ chối mọi yêu cầu bài đăng với loại nội dung khác ngoài ứng dụng/X-www-form-urlencoded | Multipart/Form-Data [403]

SetEnv SERVER_ADMIN 
8

Thiếu http_host

Từ chối các yêu cầu không chứa tiêu đề máy chủ HTTP. [403]

SetEnv SERVER_ADMIN 
9

Khai thác đồ họa không có thật

Từ chối khai thác rõ ràng bằng đồ họa không có thật [403]

ServerSignature off | on | email
0

Không có người dùng, không đăng

Từ chối các yêu cầu POST của các tác nhân người dùng trống. Có thể ngăn một số lượng nhỏ khách truy cập đăng. [403]

ServerSignature off | on | email
1

Từ chối bất kỳ nỗ lực bình luận nào với trường HTTP_REFERER trống, cao cho thấy thư rác. Có thể ngăn một số khách truy cập đăng. [403]

ServerSignature off | on | email
2

Trackback Spam

Từ chối thư rác theo dõi rõ ràng. Xem Holy Shmoly! [403]

ServerSignature off | on | email
3

Ánh xạ tất cả các uris ngoại trừ các uris tương ứng với các tệp hiện có cho một trình xử lý

ServerSignature off | on | email
4

Ánh xạ bất kỳ yêu cầu nào cho người xử lý

Trong trường hợp tất cả các URI nên được gửi đến cùng một nơi (bao gồm các yêu cầu có khả năng cho nội dung tĩnh), phương pháp sử dụng phụ thuộc vào loại người xử lý. Đối với các tập lệnh PHP, hãy sử dụng: Đối với các trình xử lý khác như tập lệnh PHP, sử dụng:

ServerSignature off | on | email
5

Và cho các tập lệnh CGI:

ServerSignature off | on | email
6

Thay vào đó, bản đồ uris tương ứng với các tệp hiện có với trình xử lý

ServerSignature off | on | email
7

Nếu các tệp hiện có mà bạn muốn xử lý bởi tập lệnh của bạn, có một tập hợp các phần mở rộng tệp chung khác biệt với trình xử lý, bạn có thể bỏ qua mod_rewrite và sử dụng mod_actions thay thế. Giả sử bạn muốn tất cả các tệp .html và .tpl được xử lý bởi tập lệnh của bạn:

ServerSignature off | on | email
8

Từ chối truy cập nếu var = val chứa chuỗi foo.

ServerSignature off | on | email
9

Xóa chuỗi truy vấn

AddDefaultCharset UTF-8
DefaultLanguage en-US
0

Thêm vào chuỗi truy vấn

Giữ chuỗi truy vấn hiện có bằng cách sử dụng cờ chuỗi truy vấn, nhưng thêm var = val vào cuối.

AddDefaultCharset UTF-8
DefaultLanguage en-US
1

Viết lại cho một số chuỗi truy vấn nhất định

Viết lại các URL như https://www.askapache.com/url1?var=val đến https://www.askapache.com/url2?var=val nhưng không viết lại nếu Val không có.

AddDefaultCharset UTF-8
DefaultLanguage en-US
2

Sửa đổi chuỗi truy vấn

Thay đổi bất kỳ phiên bản nào của Val trong chuỗi truy vấn thành Other_val khi truy cập /đường dẫn. Lưu ý rằng %1 và %2 là tham chiếu ngược với phần phù hợp của biểu thức chính quy trong lần viết lại trước đó.

AddDefaultCharset UTF-8
DefaultLanguage en-US
3

Best .htaccess Articles

.htaccess for Webmasters

  • Process certain requests for files using a cgi script
  • Process Requests with certain Request Methods
  • Make any file be a certain filetype
  • Use IfModule directive for robust code

Mod_Rewrite URL Rewriting

Undocumented techniques and methods will allow you to utilize mod_rewrite at an "expert level" by showing you how to unlock its secrets.

  • Check for a key in QUERY_STRING
  • Block access to files during certain hours of the day
  • Rewrite underscores to hyphens for SEO URL
  • Redirecting Wordpress Feeds to Feedburner

301 Redirects without mod_rewrite

  • Redirect single url
  • Redirect to new Domain

Secure PHP with .htaccess

Hướng dẫn add php handler htaccess - thêm htaccess trình xử lý php
If you have a php.cgi or php.ini file in your /cgi-bin/ directory or other pub directory, try requesting them from your web browser. If your php.ini shows up or worse you are able to execute your php cgi, you'll need to secure it ASAP. This shows several ways to secure these files, and other interpreters like perl, fastCGI, bash, csh, etc.

Hướng dẫn add php handler htaccess - thêm htaccess trình xử lý php
Fresh .htaccess code for you! Check out the Cookie Manipulation and environment variable usage with mod_rewrite! I also included a couple Mod_Security .htaccess examples. Enjoy!

  • Mod_Rewrite .htaccess Examples
  • Cookie Manipulation and Tests with mod_rewrite
  • Setting Environment Variables
  • Using the Environment Variable
  • Mod_Security .htaccess Examples

.htaccess Caching

  • Speed Up Sites with htaccess Caching
  • htaccess time cheat sheet

Password Protection and Authentication

  • Require password for single file
  • Example .htaccess file for password protection
  • Prevent Caching 100%
  • Remove IE imagetoolbar without meta tag
  • Add Privacy (P3P) Header to your site
  • Add language and charset headers without meta tags

Blocking Spam and bad Bots

Hướng dẫn add php handler htaccess - thêm htaccess trình xử lý php
Want to block a bad robot or web scraper using .htaccess files? Here are 2 methods that illustrate blocking 436 various user-agents. You can block them using either SetEnvIf methods, or by using Rewrite Blocks.

PHP htaccess tips

By using some cool .htaccess tricks we can control PHP to be run as a cgi or a module. If php is run as a cgi then we need to compile it ourselves or use .htaccess to force php to use a local php.ini file. If it is running as a module then we can use various directives supplied by that modules in .htaccess

  • When php run as CGI
  • Use a custom php.ini with mod_php or php as a cgi
  • When php run as Apache Module (mod_php)
  • When cgi php is run with wrapper (FastCGI)

HTTP to HTTPS Redirects with mod_rewrite

Hướng dẫn add php handler htaccess - thêm htaccess trình xử lý php
This is freaking sweet if you use SSL I promise you! Basically instead of having to check for HTTPS using a
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
RewriteRule .? - [F]
2 for every redirect that can be either HTTP or HTTPS, I set an environment variable once with the value "http" or "https" if HTTP or HTTPS is being used for that request, and use that env variable in the RewriteRule.

SSL in .htaccess

  • Redirect non-https requests to https server
  • Rewrite non-https to HTTPS without mod_ssl!
  • Redirect everything served on port 80 to HTTPS URI

SetEnvIf and SetEnvIfNoCase in .htaccess

  • Unique mod_setenvif Variables
  • Populates HTTP_MY_ Variables with mod_setenvif variable values
  • Allows only if HOST Header is present in request
  • Add values from HTTP Headers

Site Security with .htaccess

chmod .htpasswd files 640, chmod .htaccess 644, php files 600, and chmod files that you really dont want people to see as 400. (NEVER chmod 777, try 766)

  • CHMOD your files
  • Prevent access to .htaccess and .htpasswd files
  • Show Source Code instead of executing
  • Securing directories: Remove ability to execute scripts
  • .htaccess ErrorDocuments

Merging Notes

The order of merging is:

  1. RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
    RewriteRule .? - [F]
    
    3 (except regular expressions) and .htaccess done simultaneously (with .htaccess, if allowed, overriding
    RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
    RewriteRule .? - [F]
    
    3)
  2. RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
    RewriteRule .? - [F]
    
    5 (and
    RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
    RewriteRule .? - [F]
    
    6)
  3. RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
    RewriteRule .? - [F]
    
    7 and
    RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
    RewriteRule .? - [F]
    
    8 done simultaneously
  4. RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
    RewriteRule .? - [F]
    
    9 and
    AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4
    0 done simultaneously

These are just some of my favorite .htaccess resources. I'm really into doing your own hacking to get knowledge and these links are all great resources in that respect. I'm really interested in new or unusual htaccess solutions or htaccess hacks using .htaccess files, so let me know if you find one.

NCSA HTTPd Tutorials Robert Hansen Here's a great Hardening HTAccess part 1, part 2, part 3 article that goes into detail about some of the rarer security applications for .htaccess files. SAMAXES Some very detailed and helpful .htaccess articles, such as the ".htaccess - gzip and cache your site for faster loading and bandwidth saving." PerishablePress Stupid .htaccess tricks is probably the best explanation online for many of the best .htaccess solutions, including many from this page. Unlike me they are fantastic writers, even for technical stuff they are very readable, so its a good blog to kick back on and read. They also have a fantastic article detailing how to block/deny specific requests using mod_rewrite. BlogSecurity Mostly a site for... blog security (which is really any web-app security) this blog has a few really impressive articles full of solid information for Hardening WordPress with .htaccess among more advanced topics that can be challenging but effective. This is a good site to subscribe to their feed, they publish plugin exploits and wordpress core vulnerabilities quite a bit. Check-These Oldschool security/unix dude with some incredibly detailed mod_rewrite tutorials, helped me the most when I first got into this, and a great guy too. See: Basic Mod_Rewrite Guide, and Advanced Mod_Rewrite Tutorial Reaper-X Alot of .htaccess tutorials and code. See: Hardening Wordpress with Mod Rewrite and htaccess jdMorgan jdMorgan is the Moderator of the Apache Forum at WebmasterWorld, a great place for answers. In my experience he can answer any tough question pertaining to advanced .htaccess usage, haven't seen him stumped yet. The W3C Setting Charset in .htaccess is very informative. Holy Shmoly! A great blogger with analysis of attacks and spam. See: More ways to stop spammers and unwanted traffic. Apache Week A partnership with Red Hat back in the 90's that produced some excellent documentation. Corz Here's a resource that I consider to have some of the most creative and ingenious ideas for .htaccess files, although the author is somewhat of a character ;) Its a trip trying to navigate around the site, a fun trip. Its like nothing I've ever seen. There are only a few articles on the site, but the htaccess articles are very original and well-worth a look. See: htaccess tricks and tips.

Htaccess Directives

This is an AskApache.com exclusive you won't find this anywhere else.

AcceptFilter, AcceptMutex, AcceptPathInfo, AccessFileName, Action, AddAlt, AddAltByEncoding, AddAltByType, AddCharset, AddDefaultCharset, AddDescription, AddEncoding, AddHandler, AddIcon, AddIconByType, AddIconByEncoding, AddIconByEncoding, AddIconByType, AddInputFilter, AddLanguage, AddModuleInfo, AddOutputFilterByType, AddOutputFilter, AddOutputFilterByType, AddType, Alias, ScriptAlias, ServerAlias, AliasMatch, Allow, AllowOverride, AllowEncodedSlashes, _ROUTING__allow_GET, _ROUTING__allow_HEAD, _ROUTING__allow_POST, Allow, AllowOverride, AllowEncodedSlashes, AllowCONNECT, AllowEncodedSlashes, AllowMethods, AllowOverride, AllowOverrideList, Anonymous, Anonymous_LogEmail, Anonymous_NoUserID, Anonymous_Authoritative, Anonymous_LogEmail, Anonymous_MustGiveEmail, Anonymous_NoUserId, Anonymous_VerifyEmail, AssignUserID, AsyncRequestWorkerFactor, AuthAuthoritative, AuthBasicAuthoritative, AuthBasicFake, AuthBasicProvider, AuthBasicUseDigestAlgorithm, AuthDBDUserPWQuery, AuthDBDUserRealmQuery, AuthDBMAuthoritative, AuthDBMGroupFile, AuthDBMType, AuthDBMUserFile, AuthDefaultAuthoritative, AuthDigestAlgorithm, AuthDigestDomain, AuthDigestFile, AuthDigestGroupFile, AuthDigestNcCheck, AuthDigestNonceFormat, AuthDigestNonceLifetime, AuthDigestProvider, AuthDigestQop, AuthDigestShmemSize, AuthFormAuthoritative, AuthFormBody, AuthFormDisableNoStore, AuthFormFakeBasicAuth, AuthFormLocation, AuthFormLoginRequiredLocation, AuthFormLoginSuccessLocation, AuthFormLogoutLocation, AuthFormMethod, AuthFormMimetype, AuthFormPassword, AuthFormProvider, AuthFormSitePassphrase, AuthFormSize, AuthFormUsername, AuthGroupFile, AuthLDAPAuthoritative, AuthLDAPAuthorizePrefix, AuthLDAPAuthzEnabled, AuthLDAPBindAuthoritative, AuthLDAPBindDN, AuthLDAPBindPassword, AuthLDAPCharsetConfig, AuthLDAPCompareAsUser, AuthLDAPCompareDNOnServer, AuthLDAPDereferenceAliases, AuthLDAPEnabled, AuthLDAPFrontPageHack, AuthLDAPGroupAttribute, AuthLDAPGroupAttributeIsDN, AuthLDAPGroupAttributeIsDN, AuthLDAPInitialBindAsUser, AuthLDAPInitialBindPattern, AuthLDAPMaxSubGroupDepth, AuthLDAPRemoteUserAttribute, AuthLDAPRemoteUserIsDN, AuthLDAPSearchAsUser, AuthLDAPSubGroupAttribute, AuthLDAPSubGroupClass, AuthLDAPURL, AuthMerging, AuthName, AuthnCacheContext, AuthnCacheEnable, AuthnCacheProvideFor, AuthnCacheProvider, AuthnCacheSOCache, AuthnCacheTimeout, AuthnzFcgiCheckAuthnProvider, AuthnzFcgiDefineProvider, AuthType, AuthUserFile, AuthzDBDLoginToReferer, AuthzDBDQuery, AuthzDBDRedirectQuery, AuthzDBMAuthoritative, AuthzDBMType, AuthzDefaultAuthoritative, AuthzGroupFileAuthoritative, AuthzLDAPAuthoritative, AuthzOwnerAuthoritative, AuthzSendForbiddenOnFailure, AuthzUserAuthoritative, BalancerGrowth, BalancerInherit, BalancerMember, BalancerNonce, BalancerPersist, BrowserMatch, BrowserMatchNoCase, BrowserMatchNoCase, BS2000Account, BufferedLogs, DeflateBufferSize, BufferSize, CacheDefaultExpire, CacheDetailHeader, CacheDirLength, CacheDirLevels, CacheDisable, CacheEnable, CacheExpiryCheck, cachefile, CacheForceCompletion, CacheGcClean, CacheGcDaily, CacheGcInterval, CacheGcMemUsage, CacheGcUnused, CacheHeader, CacheIgnoreCacheControl, CacheIgnoreHeaders, CacheIgnoreNoLastMod, CacheIgnoreQueryString, CacheIgnoreURLSessionIdentifiers, CacheKeyBaseURL, CacheLastModifiedFactor, CacheLock, CacheLockMaxAge, CacheLockPath, CacheMaxExpire, CacheMaxFileSize, CacheMinExpire, CacheMinFileSize, CacheNegotiatedDocs, CacheQuickHandler, CacheReadSize, CacheReadTime, CacheRoot, MCacheSize, CacheSocache, CacheSocacheMaxSize, CacheSocacheMaxTime, CacheSocacheMinTime, CacheSocacheReadSize, CacheSocacheReadTime, CacheStaleOnError, CacheStoreExpired, CacheStoreNoStore, CacheStorePrivate, CacheTimeMargin, CaseFilter, CaseFilterIn, CGIDScriptTimeout, CGIMapExtension, CGIPassAuth, CGIVar, CharsetDefault, CharsetOptions, CharsetSourceEnc, CheckCaseOnly, CheckSpelling, ChildperUserID, ChrootDir, ClientRecheckTime, ContentDigest, CookieDomain, CookieExpires, CookieLog, CookieName, CookieStyle, CookieTracking, CoreDumpDirectory, CustomLog, DAV, DAVDepthInfinity, DAVGenericLockDB, DAVLockDB, DAVMinTimeout, DBDExptime, DBDInitSQL, DBDKeep, DBDMax, DBDMin, DBDParams, DBDPersist, DBDPrepareSQL, DBDriver, DefaultIcon, DefaultLanguage, DefaultRuntimeDir, DefaultType, Define, DeflateBufferSize, DeflateCompressionLevel, DeflateFilterNote, DeflateInflateLimitRequestBody, DeflateInflateRatioBurst, DeflateInflateRatioLimit, DeflateMemLevel, DeflateWindowSize, Deny, Deny, DirectoryIndex, DirectorySlash, DirectoryCheckHandler, DirectoryIndex, DirectoryIndexRedirect, DirectoryMatch, DirectorySlash, VirtualDocumentRoot, DocumentRoot, DTracePrivileges, DumpIOInput, DumpIOLogLevel, DumpIOOutput, EnableExceptionHook, EnableMMAP, EnableSendfile, ErrorDocument, ErrorLog, ErrorLogFormat, ExpiresActive, ExpiresByType, ExpiresDefault, ExtendedStatus, ExtFilterDefine, ExtFilterOptions, FallbackResource, FancyIndexing, FileETag, Files, FilesMatch, FilterChain, FilterDeclare, FilterProtocol, FilterProvider, FilterTrace, ForceLanguagePriority, ForceType, ForensicLog, GlobalLog, GprofDir, AuthGroupFile, Group, AuthDBMGroupFile, AuthLDAPGroupAttribute, AuthLDAPGroupAttributeIsDN, AuthzGroupFileAuthoritative, H2AltSvc, H2AltSvcMaxAge, H2Direct, H2MaxSessionStreams, H2MaxWorkerIdleSeconds, H2MaxWorkers, H2MinWorkers, H2ModernTLSOnly, H2Push, H2PushDiarySize, H2PushPriority, H2SerializeHeaders, H2SessionExtraFiles, H2StreamMaxMemSize, H2TLSCoolDownSecs, H2TLSWarmUpSize, H2Upgrade, H2WindowSize, Header, RequestHeader, HeaderName, HeaderName, HeartbeatAddress, HeartbeatListen, HeartbeatMaxServers, HeartbeatStorage, HostnameLookups, IdentityCheck, IdentityCheckTimeout, IfDefine, IfModule, IfVersion, ImapBase, ImapDefault, ImapMenu, Include, IncludeOptional, IndexHeadInsert, IndexIgnore, IndexIgnoreReset, IndexOptions, IndexOrderDefault, IndexStyleSheet, InputSed, ISAPIAppendLogToErrors, ISAPIAppendLogToQuery, ISAPICacheFile, ISAPIFakeAsync, ISAPILogNotSupported, ISAPIReadAheadBuffer, KeepAlive, KeepAliveTimeout, MaxKeepAliveRequests, KeepAliveTimeout, KeptBodySize, LanguagePriority, ForceLanguagePriority, LDAPCacheEntries, LDAPCacheTTL, LDAPConnectionPoolTTL, LDAPConnectionTimeout, LDAPLibraryDebug, LDAPOpCacheEntries, LDAPOpCacheTTL, LDAPReferralHopLimit, LDAPReferrals, LDAPRetries, LDAPRetryDelay, LDAPSharedCacheFile, LDAPSharedCacheSize, LDAPTimeout, LDAPTrustedCA, LDAPTrustedCAType, LDAPTrustedClientCert, LDAPTrustedGlobalCert, LDAPTrustedMode, LDAPVerifyServerCert, LimitRequestBody, RLimitMEM, LimitRequestFields, LimitRequestFieldSize, LimitRequestLine, LimitExcept, LimitInternalRecursion, LimitRequestBody, LimitRequestFields, LimitRequestFieldsize, LimitRequestLine, LimitXMLRequestBody, LoadFile, LoadModule, Location, LocationMatch, LockFile, LogFormat, LogIOTrackTTFB, RewriteLogLevel, LogLevel, LogMessage, LuaAuthzProvider, Lua_____ByteCodeHack, LuaCodeCache, LuaHookAccessChecker, LuaHookAuthChecker, LuaHookCheckUserID, LuaHookFixups, LuaHookInsertFilter, LuaHookLog, LuaHookMapToStorage, LuaHookTranslateName, LuaHookTypeChecker, LuaInherit, LuaInputFilter, LuaMapHandler, LuaOutputFilter, LuaPackageCPath, LuaPackagePath, LuaQuickHandler, LuaRoot, LuaScope, MaxClientConnections, MaxClients, MaxConnectionsPerChild, MaxKeepAliveRequests, MaxMemFree, MaxRangeOverlaps, MaxRangeReversals, MaxRanges, MaxRequestsPerChild, MaxRequestsPerThread, MaxRequestWorkers, MaxSpareServers, MaxSpareThreads, MaxThreads, MaxThreadsPerChild, MCacheMaxObjectCount, MCacheMaxObjectSize, MCacheMaxStreamingBuffer, MCacheMinObjectSize, MCacheRemovalAlgorithm, MCacheSize, MemcacheConnTTL, MergeTrailers, MetaDir, MetaFiles, MetaSuffix, MimeMagicFile, MinSpareServers, MinSpareThreads, mmapfile, ModemStandard, ModMimeUsePathInfo, MultiviewsMatch, Mutex, NameVirtualHost, NoProxy, NumServers, NWSSLTrustedCerts, NWSSLUpgradeable, Options, RewriteOptions, IndexOptions, Order, IndexOrderDefault, Order, IndexOrderDefault, OutputSed, PassEnv, php_admin_flag, php_admin_value, php_flag, php_value, PidFile, Port, PrivilegesMode, FilterProtocol, Protocol, ProtocolEcho, Protocols, ProtocolsHonorOrder, ProxyPass, ProxyPassMatch, ProxyPassReverse, ProxyRequests, ProxyAddHeaders, ProxyBadHeader, ProxyBlock, ProxyDomain, ProxyErrorOverride, ProxyExpressDBMFile, ProxyExpressDBMType, ProxyExpressEnable, ProxyFtpDirCharset, ProxyFtpEscapeWildcards, ProxyFtpListOnWildcard, ProxyHCExpr, ProxyHCTemplate, ProxyHCTPsize, ProxyHTMLBufSize, ProxyHTMLCharsetOut, ProxyHTMLDoctype, ProxyHTMLEnable, ProxyHTMLEvents, ProxyHTMLExtended, ProxyHTMLFixups, ProxyHTMLInterp, ProxyHTMLLinks, ProxyHTMLMeta, ProxyHTMLStripComments, ProxyHTMLURLMap, ProxyIOBufferSize, ProxyMatch, ProxyMaxForwards, ProxyPass, ProxyPassMatch, ProxyPassReverse, ProxyPassInherit, ProxyPassInterpolateEnv, ProxyPassMatch, ProxyPassReverse, ProxyPassReverseCookieDomain, ProxyPassReverseCookiePath, ProxyPreserveHost, ProxyReceiveBufferSize, ProxyRemote, ProxyRemoteMatch, ProxyRequests, ProxySCGIInternalRedirect, ProxySCGISendfile, ProxySet, ProxySourceAddress, ProxyStatus, ProxyTimeout, ProxyVia, QualifyRedirectURL, ReadmeName, Redirect, RedirectMatch, RedirectTemp, RedirectPermanent, RedirectMatch, RedirectPermanent, RedirectTemp, ReflectorHeader, RemoteIPHeader, RemoteIPInternalProxy, RemoteIPInternalProxyList, RemoteIPProxiesHeader, RemoteIPTrustedProxy, RemoteIPTrustedProxyList, RemoveCharset, RemoveEncoding, RemoveHandler, RemoveInputFilter, RemoveLanguage, RemoveOutputFilter, RemoveType, RequestHeader, RequestReadTimeout, RequestTimeout, Require, RewriteBase, RewriteCond, RewriteEngine, RewriteLock, RewriteLog, RewriteLogLevel, RewriteLogLevel, RewriteMap, RewriteOptions, RewriteRule, RLimitCPU, RLimitMEM, RLimitNPROC, Satisfy, ScoreboardFile, ScoreBoardFile, Script, ScriptAlias, ScriptAlias, ScriptAliasMatch, ScriptInterpreterSource, ScriptLog, ScriptLogBuffer, ScriptLogLength, Scriptsock, ScriptSock, SecureListen, SeeRequestTail, SerfCluster, SerfPass, ServerAdmin, ServerAlias, ServerLimit, ServerName, ServerPath, ServerRoot, ServerSignature, ServerTokens, Session, SessionCookieName, SessionCookieName2, SessionCookieRemove, SessionCryptoCipher, SessionCryptoDriver, SessionCryptoPassphrase, SessionCryptoPassphraseFile, SessionDBDCookieName, SessionDBDCookieName2, SessionDBDCookieRemove, SessionDBDDeleteLabel, SessionDBDInsertLabel, SessionDBDPerUser, SessionDBDSelectLabel, SessionDBDUpdateLabel, SessionEnv, SessionExclude, SessionHeader, SessionInclude, SessionMaxAge, SetEnvIfNoCase, SetEnv, SetEnvIf, SetEnvIfNoCase, SetEnvIf, SetEnvIfExpr, SetEnvIfNoCase, SetHandler, SetInputFilter, SetOutputFilter, SimpleProcCount, SimpleThreadCount, SSIAccessEnable, SSIEndTag, SSIErrorMsg, SSIEtag, SSILastModified, SSILegacyExprParser, SSIStartTag, SSITimeFormat, SSIUndefinedEcho, SSLLog, SSLLogLevel, StartServers, StartThreads, Substitute, SubstituteInheritBefore, SubstituteMaxLineLength, Suexec, SuexecUserGroup, ThreadLimit, ThreadsPerChild, ThreadStackSize, KeepAliveTimeout, AuthnCacheTimeout, TraceEnable, TransferLog, TrustedProxy, TypesConfig, UnDefine, UnsetEnv, UseCanonicalName, UseCanonicalPhysicalPort, User, AuthUserFile, UserDir, AuthDBMUserFile, Anonymous_NoUserID, UserDir, VHostCGIMode, VHostCGIPrivs, VHostGroup, VHostPrivs, VHostSecure, VHostUser, VirtualDocumentRoot, VirtualDocumentRootIP, VirtualHost, VirtualScriptAlias, VirtualScriptAliasIP, Win32DisableAcceptEx, XBitHack, xml2EncAlias, xml2EncDefault, xml2StartParse

Htaccess Variables

alias-forced-type, API_VERSION, ap-mime-exceptions-list, AP_PARENT_PID, AUTHN_PROVIDER_GROUP, AUTH_TYPE, BALANCER, BALANCER_NAME, BALANCER_ROUTE_CHANGED, BALANCER_SESSION_ROUTE, BALANCER_SESSION_STICKY, BALANCER_WORKER_NAME, BALANCER_WORKER_ROUTE, CACHE, CACHE_CONDITIONAL, CACHE_INVALIDATE, CACHE_OUT, CACHE_OUT_SUBREQ, CACHE_REMOVE_URL, CACHE_SAVE, CACHE_SAVE_SUBREQ, CERT, CERT_BASE64, CERT_DER, CERT_KEY3_DB, CERT_NICKNAME, CERT_PFX, CGI_APACHE_ROLE, CGI_ROLE, CLIENT_CERT_RFC4523_CEA, CLIENT_VERIFY, COMPRESS_METHOD, CONNECTION, CONN_LOG_ID, CONN_REMOTE_ADDR, CONTENT_LENGTH, CONTENT_SET, CONTENT_TYPE, CONTEXT_DOCUMENT_ROOT, CONTEXT_PREFIX, DATE_GMT, DATE_LOCAL, DEFLATE, DOCUMENT_ARGS, DOCUMENT_NAME, DOCUMENT_PATH_INFO, DOCUMENT_ROOT, DOCUMENT_URI, downgrade-1.0, ENV, ENVVAR_SCRIPT_URI, ENVVAR_SCRIPT_URL, ERRFN_USERDATA_KEY, error-notes, ERROR_NOTES, FCGI_APACHE_ROLE, FCGI_ROLE, filter-errordocs, force-gzip, force-no-vary, force-proxy-request-1.0, force-response-1.0, forensic-id, GATEWAY_INTERFACE, GET, HANDLER, HTTP_ACCEPT, HTTP_ACCEPT_CHARSET, HTTP_ACCEPT_ENCODING, HTTP_ACCEPT_LANGUAGE, HTTP_CACHE_CONTROL, HTTP_CONNECTION, HTTP_COOKIE, HTTP_FORWARDED, HTTP_HOST, HTTP_KEEP_ALIVE, HTTP_PC_REMOTE_ADDR, HTTP_PROXY_CONNECTION, HTTP_REFERER, HTTP_REQUEST, HTTPS, HTTPS_HOST, HTTP_TE, HTTP_TRAILER, HTTP_TRANSFER_ENCODING, HTTP_UPGRADE, HTTP_USER_AGENT, HTTP_USER_AGENT, HTTP_WP_VERSION_FOLDER_NAME, If-Modified-Since, If-None-Match, INCLUDES, INFLATE, installpath, IPV6, IS_SUBREQ, KEY_BASE64, KEY_DER, KEY_PFX, LAST_MODIFIED, LDAP_BINDASUSER, mod_rewrite_rewritten, mod_userdir_user, no-cache, no-etag, no-gzip, nokeepalive, nwconv-ssl, ORIGIN, origin_is, ORIGIN_SUB_DOMAIN, ORIG_PATH_INFO, ORIG_PATH_TRANSLATED, ORIG_SCRIPT_FILENAME, ORIG_SCRIPT_NAME, PATH_INFO, PATH_TRANSLATED, PHP_SELF, PLATFORM, POST, Pragma, Profile, PROTO, Protocol, PROTOCOL, protossl, PROXY_CONNECTION, proxy-error-override, proxy-fcgi-pathinfo, proxy-flushall, PROXY_HTML_FORCE, proxy-initial-not-pooled, proxy-interim-response, proxy-nocanon, proxy-nokeepalive, proxy-noquery, proxy-scgi-pathinfo, proxy-sendchunked, proxy-sendchunks, proxy-sendcl, proxy-sendextracrlf, proxy-sendunchangedcl, proxy-source-port, proxy-status, proxy_timedout, P_SUFFIX, push-policy, PUT, QUERY_STRING, QUERY_STRING, QUERY_STRING_UNESCAPED, rate-limit, REDIRECT_BREAKPOINT, redirect-carefull, redirect-carefully, REDIRECT_ENVVAR_SCRIPT_URL, REDIRECT_QUERY_STRING, REDIRECT_REDIRECT_STATUS, REDIRECT_REMOTE_USER, REDIRECT_STATUS, REDIRECT_UNIQUE_ID, REDIRECT_URL, REDIRECT_X_REWRITE, REMOTE_ADDR, REMOTE_HOST, REMOTE_IDENT, remoteip-proxy-ip-list, REMOTE_PASSWD, REMOTE_PORT, REMOTE_USER, REQUEST_ACCESS, REQUEST_FILENAME, REQUEST_FILENAME, REQUEST_FILENAME, REQUEST_FILNAME, REQUEST_LOG_ID, REQUEST_METHOD, REQUEST_SCHEME, REQUEST_STATUS, REQUEST_TIME, REQUEST_URI, REQUEST_URI, REQUEST_URI, REQUEST_URL, RewriteBase, REWRITEBASE, rewrite-proxy, _ROUTING__allow_GET, _ROUTING__allow_HEAD, _ROUTING__allow_POST, SCRIPT_FILENAME, SCRIPT_GROUP, SCRIPT_NAME, SCRIPT_URI, SCRIPT_URL, SCRIPT_USER, SEARCH, SECURE_RENEG, SERVER_ADDR, SERVER_ADMIN, SERVER_NAME, SERVER_PORT, SERVER_PORT_SECURE, SERVER_PROTOCOL, SERVER_SIGNATURE, SERVER_SOFTWARE, SESSION_ID, session-route, session-sticky, short-lingering-close, site_dir, SRP_USER, SRP_USERINFO, ssl-access-forbidden, SSL_CIPHER, SSL_CIPHER_ALGKEYSIZE, SSL_CIPHER_EXPORT, SSL_CIPHER_USEKEYSIZE, SSL_CLIENT_A_KEY, SSL_CLIENT_A_SIG, SSL_CLIENT_CERT, SSL_CLIENT_CERT_RFC4523_CEA, SSL_CLIENT_I_DN, SSL_CLIENT_I_DN_C, SSL_CLIENT_I_DN_CN, SSL_CLIENT_I_DN_D, SSL_CLIENT_I_DN_G, SSL_CLIENT_I_DN_I, SSL_CLIENT_I_DN_L, SSL_CLIENT_I_DN_O, SSL_CLIENT_I_DN_OU, SSL_CLIENT_I_DN_S, SSL_CLIENT_I_DN_ST, SSL_CLIENT_I_DN_T, SSL_CLIENT_I_DN_UID, SSL_CLIENT_M_SERIAL, SSL_CLIENT_M_VERSION, SSL_CLIENT_SAN_DNS, SSL_CLIENT_S_DN, SSL_CLIENT_S_DN_C, SSL_CLIENT_S_DN_CN, SSL_CLIENT_S_DN_D, SSL_CLIENT_S_DN_G, SSL_CLIENT_S_DN_I, SSL_CLIENT_S_DN_L, SSL_CLIENT_S_DN_O, SSL_CLIENT_S_DN_OU, SSL_CLIENT_S_DN_S, SSL_CLIENT_S_DN_ST, SSL_CLIENT_S_DN_T, SSL_CLIENT_S_DN_UID, SSL_CLIENT_V_END, SSL_CLIENT_VERIFY, SSL_CLIENT_V_REMAIN, SSL_CLIENT_V_START, SSL_COMPRESS_METHOD, SSL_PROTOCOL, ssl-renegotiate-forbidden, ssl-secure-reneg, SSL_SECURE_RENEG, SSL_SERVER_A_KEY, SSL_SERVER_A_SIG, SSL_SERVER_CERT, SSL_SERVER_I_DN, SSL_SERVER_I_DN_C, SSL_SERVER_I_DN_CN, SSL_SERVER_I_DN_D, SSL_SERVER_I_DN_G, SSL_SERVER_I_DN_I, SSL_SERVER_I_DN_L, SSL_SERVER_I_DN_O, SSL_SERVER_I_DN_OU, SSL_SERVER_I_DN_S, SSL_SERVER_I_DN_ST, SSL_SERVER_I_DN_T, SSL_SERVER_I_DN_UID, SSL_SERVER_M_SERIAL, SSL_SERVER_M_VERSION, SSL_SERVER_SAN_DNS, SSL_SERVER_S_DN, SSL_SERVER_S_DN_C, SSL_SERVER_S_DN_CN, SSL_SERVER_S_DN_D, SSL_SERVER_S_DN_G, SSL_SERVER_S_DN_I, SSL_SERVER_S_DN_L, SSL_SERVER_S_DN_O, SSL_SERVER_S_DN_OU, SSL_SERVER_S_DN_S, SSL_SERVER_S_DN_ST, SSL_SERVER_S_DN_T, SSL_SERVER_S_DN_UID, SSL_SERVER_V_END, SSL_SERVER_V_START, SSL_SESSION_ID, SSL_SESSION_RESUMED, SSL_SRP_USER, SSL_SRP_USERINFO, SSL_TLS_SNI, SSL_VERSION_INTERFACE, SSL_VERSION_LIBRARY, SSL_VERSION_LIBRARY_INTERFACE, SSL_VERSION_PRODUCT, static, SUB_PATH, THE_REQUEST, TIME, TIME_DAY, TIME_HOUR, TIME_MIN, TIME_MON, TIME_SEC, TIME_WDAY, TIME_YEAR, TLS_SNI, TZ, uds_path, UNIQUE_ID, UNMAPPED_REMOTE_USER, USERAGENT_VIA, USER_NAME, usingSSL, variant-list, VARIANTS, verbose-error-to, W3TC_DOMAIN, W3TC_ENC, W3TC_PREVIEW, W3TC_REF, W3TC_SSL, W3TC_UA, WRDFNC_ENC, WRDFNC_HTTPS, XAUTHORIZATION, X_FORWARDED_FOR, X-Forwarded-Proto, X-Forwarded-Server, X-Forwarded-SSL, XPROXY_CONNECTION, X-Requested-With, X-Wap-Profile, ZIP_EXT

Mô -đun HTACCESS

Dưới đây là hầu hết các mô -đun đi kèm với Apache. Mỗi người có thể có các lệnh mới có thể được sử dụng trong phạm vi tệp .htaccess. mod_actions, mod_alias, mod_asis, mod_auth_basic, mod_auth_digest, mod_authn_anon, mod_authn_dbd, mod_authn_dbm, mod_authn_default, mod_authn_file, mod_authz_dbm, mod_authz_default, mod_authz_groupfile, mod_authz_host, mod_authz_owner, mod_authz_user, mod_autoindex, mod_cache, mod_cern_meta, mod_cgi, mod_dav, mod_dav_fs, mod_dbd, mod_deflate, mod_dir, mod_disk_cache, mod_dumpio, mod_env, mod_expires, mod_ext_filter, mod_file_cache, mod_filter, mod_headers, mod_ident, mod_imagemap, mod_include, mod_info, mod_log_config, mod_log_forensic, mod_logio, mod_mem_cache, mod_mime, mod_mime_magic, mod_negotiation, mod_proxy, mod_proxy_ajp, mod_proxy_balancer, mod_proxy_connect, mod_proxy_ftp, mod_proxy_http, mod_rewrite, mod_setenvif, mod_speling, mod_ssl, mod_status, mod_subst acad, mod_unique_id, mod_userdir, mod_usertrack, mod_version, mod_vhost_alias

Phần mềm HTACCESS

Máy chủ Apache HTTP đi kèm với các chương trình sau.

AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4
1Apache siêu văn bản chuyển giao hàng Máy chủ
AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4
2Apache Giao diện điều khiển máy chủ HTTP ____93Apache HTTP Máy chủ Điểm chuẩn Công cụ đánh dấu ____ Các tệp xác thực để xác thực cơ bản ____101create các tệp dbm để sử dụng với rewritemap.

Nhìn kỹ thuật về .htaccess

Nguồn: Ghi chú API APACHE

Cấu trúc cấu hình mỗi định hướng

Chúng ta hãy xem xét tất cả những điều này diễn ra trong mod_mime.c, trong đó xác định trình xử lý gõ tệp mô phỏng hành vi của máy chủ NCSA về việc xác định các loại tệp từ hậu tố. Những gì chúng ta sẽ xem xét, ở đây, là mã thực hiện các lệnh AddType và AddenCoding. Các lệnh này có thể xuất hiện trong các tệp .htaccess, vì vậy chúng phải được xử lý trong dữ liệu trực tiếp riêng của mô-đun, trên thực tế, bao gồm hai bảng riêng biệt cho các loại MIME và thông tin mã hóa, và được khai báo như sau:

AddDefaultCharset UTF-8
DefaultLanguage en-US
4

Khi máy chủ đang đọc một tệp cấu hình hoặc phần, bao gồm một trong các lệnh của mô -đun MIME, nó cần tạo cấu trúc mime_dir_config, vì vậy các lệnh đó có một cái gì đó để hành động. Nó thực hiện điều này bằng cách gọi chức năng mà nó tìm thấy trong mô-đun của khe cấu hình per-DIR ', với hai đối số: tên của thư mục mà thông tin cấu hình này được áp dụng (hoặc null cho srm.conf) và một con trỏ tới một Nhóm tài nguyên trong đó phân bổ nên xảy ra. . Cấu trúc được tạo ra để biến mất khi hồ bơi được xóa, bằng cách đăng ký dọn dẹp trên hồ bơi nếu cần thiết). Đối với mô-đun MIME, chức năng tạo cấu hình mỗi DIR chỉ cần ap_pallocs cấu trúc ở trên và tạo ra một vài bảng để điền vào nó. Trông như thế này:

AddDefaultCharset UTF-8
DefaultLanguage en-US
5

Bây giờ, giả sử chúng ta vừa đọc trong tệp .htaccess. Chúng tôi đã có cấu trúc cấu hình mỗi phương thức cho thư mục tiếp theo trong hệ thống phân cấp. Nếu tệp .htaccess chúng ta vừa đọc trong không có bất kỳ lệnh addtype hoặc addenCoding nào, cấu trúc cấu hình mỗi phương pháp của nó cho mô-đun MIME vẫn còn hiệu lực và chúng ta chỉ có thể sử dụng nó. Nếu không, chúng ta cần hợp nhất hai cấu trúc bằng cách nào đó. Để làm điều đó, máy chủ sẽ gọi hàm hợp nhất cấu hình mỗi phương thức của mô-đun, nếu có mặt. Hàm đó có ba đối số: hai cấu trúc được hợp nhất và một nhóm tài nguyên để phân bổ kết quả. Đối với mô-đun MIME, tất cả những gì cần phải thực hiện là phủ lên các bảng từ cấu trúc cấu hình mỗi phương thức mới với các bảng từ cha mẹ:

AddDefaultCharset UTF-8
DefaultLanguage en-US
6

Như một lưu ý --- nếu không có chức năng hợp nhất mỗi phương thức, máy chủ sẽ chỉ sử dụng thông tin cấu hình của thư mục con và bỏ qua cha mẹ. Đối với một số mô-đun, hoạt động tốt (ví dụ: đối với mô-đun bao gồm, có thông tin cấu hình mỗi phương thức chỉ bao gồm trạng thái của XBithack) và đối với các mô-đun đó, bạn không thể khai báo và để lại khe cấu trúc tương ứng Trong mô -đun tự null.

Command handling

Now that we have these structures, we need to be able to figure out how to fill them. That involves processing the actual AddType and AddEncoding commands. To find commands, the server looks in the module's command table. That table contains information on how many arguments the commands take, and in what formats, where it is permitted, and so forth. That information is sufficient to allow the server to invoke most command-handling functions with pre-parsed arguments. Without further ado, let's look at the AddType command handler, which looks like this (the AddEncoding command looks basically the same, and won't be shown here):

AddDefaultCharset UTF-8
DefaultLanguage en-US
7

This command handler is unusually simple. As you can see, it takes four arguments, two of which are pre-parsed arguments, the third being the per-directory configuration structure for the module in question, and the fourth being a pointer to a cmd_parms structure. That structure contains a bunch of arguments which are frequently of use to some, but not all, commands, including a resource pool (from which memory can be allocated, and to which cleanups should be tied), and the (virtual) server being configured, from which the module's per-server configuration data can be obtained if required. Another way in which this particular command handler is unusually simple is that there are no error conditions which it can encounter. If there were, it could return an error message instead of NULL; this causes an error to be printed out on the server's stderr, followed by a quick exit, if it is in the main config files; for a .htaccess file, the syntax error is logged in the server error log (along with an indication of where it came from), and the request is bounced with a server error response (HTTP error status, code 500). The MIME module's command table has entries for these commands, which look like this:

AddDefaultCharset UTF-8
DefaultLanguage en-US
8

Here's a taste of that famous Apache source code that builds the directives allowed in .htaccess file context, the key that tells whether its enabled in .htaccess context is the DIR_CMD_PERMS and then the OR_FILEINFO, which means a directive is enabled dependent on the AllowOverride directive that is only allowed in the main config. First Apache 1.3.0, then Apache 2.2.10

mod_autoindex
AddDefaultCharset UTF-8
DefaultLanguage en-US
9
mod_rewrite
Options -ExecCGI
AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
0

The entries in these tables are:

  • The name of the command
  • The function which handles it a (void *) pointer, which is passed in the cmd_parms structure to the command handler --- this is useful in case many similar commands are handled by the same function.
  • A bit mask indicating where the command may appear. There are mask bits corresponding to each AllowOverride option, and an additional mask bit, RSRC_CONF, indicating that the command may appear in the server's own config files, but not in any .htaccess file.
  • A flag indicating how many arguments the command handler wants pre-parsed, and how they should be passed in. TAKE2 indicates two pre-parsed arguments. Other options are TAKE1, which indicates one pre-parsed argument, FLAG, which indicates that the argument should be On or Off, and is passed in as a boolean flag, RAW_ARGS, which causes the server to give the command the raw, unparsed arguments (everything but the command name itself). There is also ITERATE, which means that the handler looks the same as TAKE1, but that if multiple arguments are present, it should be called multiple times, and finally ITERATE2, which indicates that the command handler looks like a TAKE2, but if more arguments are present, then it should be called multiple times, holding the first argument constant.
  • Finally, we have a string which describes the arguments that should be present. If the arguments in the actual config file are not as required, this string will be used to help give a more specific error message. (You can safely leave this NULL).

Finally, having set this all up, we have to use it. This is ultimately done in the module's handlers, specifically for its file-typing handler, which looks more or less like this; note that the per-directory configuration structure is extracted from the request_rec's per-directory configuration vector by using the ap_get_module_config function.

Side notes --- per-server configuration, virtual servers, etc.

The basic ideas behind per-server module configuration are basically the same as those for per-directory configuration; there is a creation function and a merge function, the latter being invoked where a virtual server has partially overridden the base server configuration, and a combined structure must be computed. (As with per-directory configuration, the default if no merge function is specified, and a module is configured in some virtual server, is that the base configuration is simply ignored). The only substantial difference is that when a command needs to configure the per-server private module data, it needs to go to the cmd_parms data to get at it. Here's an example, from the alias module, which also indicates how a syntax error can be returned (note that the per-directory configuration argument to the command handler is declared as a dummy, since the module doesn't actually have per-directory config data):

LITESPEED HTACCESS Hỗ trợ

Không giống như các máy chủ Web nhẹ khác, cấu hình mỗi định hướng tương thích Apache được ghi đè được hỗ trợ đầy đủ bởi máy chủ web Litespeed.Với .htacess, bạn có thể thay đổi cấu hình cho bất kỳ thư mục nào trong root tài liệu trên đường bay, trong hầu hết các trường hợp là một tính năng bắt buộc trong môi trường lưu trữ được chia sẻ.Điều đáng chú ý là cho phép hỗ trợ .htaccess trong máy chủ web Litespeed sẽ không làm giảm hiệu suất của máy chủ, so với hiệu suất giảm 40% của Apache.Tiếp tục đọc .. Sorta