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. 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
Htaccess - EvolvedThe 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 JourneySkip 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ầnOptions -ExecCGI AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi3 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 .cgi3 ). 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 theOptions -ExecCGI AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi3 sections in access.conf, or from defaults in srm.conf, which actually behaves for most purposes almost exactly likeOptions -ExecCGI AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi3). 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 HTACCESSCá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 .cgi5" 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 .cgi6. Tệp không phải là Options -ExecCGI AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi7, 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 .cgi5. Phạm vi HTACCESSKhô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ápCá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.
Ví dụ cấu hình máy chủ chínhBâ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 CNIPPETSDướ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épChuyể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 ErrordocumentSetEnv SERVER_ADMIN
|