Sorry

This feed does not validate.

In addition, interoperability with the widest range of feed readers could be improved by implementing the following recommendations.

Source: https://www.askapache.com/feed/

  1. <?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
  2. xmlns:content="http://purl.org/rss/1.0/modules/content/"
  3. xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  4. xmlns:dc="http://purl.org/dc/elements/1.1/"
  5. xmlns:atom="http://www.w3.org/2005/Atom"
  6. xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  7. xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  8. >
  9.  
  10. <channel>
  11. <title>AskApache</title>
  12. <atom:link href="https://www.askapache.com/feed/" rel="self" type="application/rss+xml" />
  13. <link>https://www.askapache.com</link>
  14. <description>Advanced Web Development</description>
  15. <lastBuildDate>Sat, 14 Dec 2019 20:52:56 +0000</lastBuildDate>
  16. <language>en-US</language>
  17. <sy:updatePeriod>
  18. hourly </sy:updatePeriod>
  19. <sy:updateFrequency>
  20. 1 </sy:updateFrequency>
  21. <item>
  22. <title>THE Ultimate Htaccess</title>
  23. <link>https://www.askapache.com/htaccess/</link>
  24. <comments>https://www.askapache.com/htaccess/#comments</comments>
  25. <pubDate>Wed, 11 Dec 2019 14:05:00 +0000</pubDate>
  26. <dc:creator><![CDATA[AskApache]]></dc:creator>
  27. <category><![CDATA[Apache]]></category>
  28. <category><![CDATA[Google]]></category>
  29. <category><![CDATA[Hosting]]></category>
  30. <category><![CDATA[Htaccess]]></category>
  31. <category><![CDATA[Optimization]]></category>
  32. <category><![CDATA[Security]]></category>
  33. <category><![CDATA[SEO]]></category>
  34. <category><![CDATA[Web Development]]></category>
  35. <category><![CDATA[WordPress]]></category>
  36. <category><![CDATA[.htpasswd]]></category>
  37. <category><![CDATA[301 Redirect]]></category>
  38. <category><![CDATA[Apache HTTP Server]]></category>
  39. <category><![CDATA[Cache]]></category>
  40. <category><![CDATA[Htaccess Software]]></category>
  41. <category><![CDATA[HTTP Headers]]></category>
  42. <category><![CDATA[httpd.conf]]></category>
  43. <category><![CDATA[HyperText Transfer Protocol]]></category>
  44. <category><![CDATA[mod_rewrite]]></category>
  45. <category><![CDATA[Redirect]]></category>
  46. <category><![CDATA[RewriteCond]]></category>
  47. <category><![CDATA[RewriteRule]]></category>
  48. <category><![CDATA[SSL]]></category>
  49.  
  50. <guid isPermaLink="false">https://www.askapache.com/htaccess/htaccesselite-ultimate-htaccess-article/</guid>
  51. <description><![CDATA[<p><a class="IFL" href="https://www.askapache.com/htaccess/" title="Htaccess"><img src="https://www.askapache.com/s/u.askapache.com/2016/07/apache-htaccess.png" alt="htaccess file" title="htaccess file" /></a> <kbd>.htaccess</kbd> is a very ancient configuration file for web servers, and is one of the most powerful configuration files most webmasters will ever come across.  This htaccess guide shows off the very <em>best of the best</em> htaccess tricks and code snippets from hackers and server administrators.</p>
  52. <p>You've come to the right place if you are looking to acquire <strong>mad skills</strong> for using .htaccess files!<br class="C" /></p>
  53. <p><a rel="nofollow" href="https://www.askapache.com/htaccess/">THE Ultimate Htaccess</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  54. ]]></description>
  55. <content:encoded><![CDATA[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.  .<dfn title="HyperText Access">htaccess</dfn> has the ability to control access/settings for the HyperText Transfer Protocol (<abbr title="HyperText Transfer Protocol">HTTP</abbr>) 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.
  56.  
  57. <a class="IFL" href="https://www.askapache.com/s/u.askapache.com/2013/04/htaccess-files.png"><img src="https://www.askapache.com/s/u.askapache.com/2013/04/htaccess-files.png" alt=".htaccess file" title=".htaccess file" width="141" height="144"></a>This is not an <em>introduction to htaccess</em>.
  58.  
  59. This is a guide for using htaccess to the fullest.
  60.  
  61. Originally (2003) this guide was known in certain hacker circles and hidden corners of the net as an <em>ultimate htaccess</em> due to the powerful htaccess tricks and tips to bypass security on a webhost, and also because many of the <a href="#htaccess_Code_Snippets">htaccess examples</a> were pretty impressive back then in that group.<br class="C">
  62. <h2>Htaccess - Evolved</h2>
  63. 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.
  64.  
  65. Htaccess file know-how will do several things for you:
  66. <ol>
  67. <li>Make your website noticeably faster.</li>
  68. <li>Allow you to debug your server.</li>
  69. <li>Make your site management easier.</li>
  70. <li>Allow you to work faster and more productively.</li>
  71. </ol>
  72. <h2>AskApache Htaccess Journey</h2>
  73. <strong>Skip this - still under edit</strong>
  74.  
  75. 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!
  76.  
  77. 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.
  78.  
  79. 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 ;)
  80. <h2>What Is .htaccess</h2>
  81. Specifically, <kbd>.htaccess</kbd> is the default file name of a special configuration file that provides a number of <a href="#Htaccess_Directives-s0">directives</a> (commands) for controlling and configuring the <a href="http://httpd.apache.org/" title="open-source HTTP server running the WWW">Apache Web Server</a>, and also to control and configure <a href="#Htaccess_Modules">modules</a> that can be built into the Apache installation, or included at run-time like mod_rewrite (for htaccess rewrite), mod_alias (for htaccess redirects), and mod_ssl (for controlling SSL connections).
  82.  
  83. <strong>Htaccess</strong> 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 <em>(DreamHost, Powweb, MediaTemple, GoDaddy) .htaccess files</em>, 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.
  84. <blockquote cite="http://httpd.apache.org/docs/1.3/misc/API.html"><strong>SKIP: </strong>History of Htaccess in 1st Apache.
  85.  
  86. 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.
  87.  
  88. 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.
  89.  
  90. Another requirement for emulating the NCSA server is being able to handle the <strong>per-directory configuration files, generally called .htaccess files</strong>, though even in the NCSA server they can contain directives which have nothing at all to do with access control. Accordingly, after URI -&gt; 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 <code>&lt;directory&gt;&lt;/directory&gt;</code> sections in access.conf, or from defaults in srm.conf, which actually behaves for most purposes almost exactly like <code>&lt;directory&gt;&lt;/directory&gt;</code>).
  91.  
  92. Finally, after having served a request which involved <strong>reading .htaccess files</strong>, 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.</blockquote>
  93. <h4>Creating Htaccess Files</h4>
  94. Htaccess files use the default filename "<code>.htaccess</code>" but any unix-style file name can be specified from the <a href="#Main_Server_Config_Examples">main server config</a> using the <code>AccessFileName</code> directive.  The file isn't <code>.htaccess.txt</code>, its literally just named <code>.htaccess</code>.
  95. <h4>Htaccess Scope</h4>
  96. Unlike the main server configuration files like <a href="https://www.askapache.com/s/u.askapache.com/2008/08/httpd-defaultconf.in">httpd.conf</a>, <strong>Htaccess files are read on every request</strong> 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).
  97. <h3>Htaccess File Syntax</h3>
  98. Htaccess files follow the same syntax as the main Apache configuration files, for powerusers here's an <a href="https://www.askapache.com/s/u.askapache.com/2009/01/apache.vim">apache.vim</a> for VI. The one main difference is the <dfn title="Whether the directive is allowed in .htaccess files">context</dfn> of the directive, which means whether or not that directive is ALLOWED to be used inside of an .htaccess file.  Htaccess files are incredibly powerful, and can also be very dangerous as some directives allowed in the main configuration files would allow users/customers to completely bypass security/bandwidth-limits/resource-limits/file-permissions, etc..  About 1/4 of all Apache directives cannot be used inside an .htaccess file (also known as a per-directory context config).  The Apache Developers are well-regarded throughout the world as being among some of the best programmers, ever.  To enable a disallowed directive inside a .htaccess file would require modifying the source code and re-compiling the server (which they allow and encourage if you are the owner/admin).
  99. <h3>Htaccess Directives</h3>
  100. <strong>Don't ask why</strong>, but I personally downloaded each major/beta release of the Apache HTTPD source code from version 1.3.0 to version 2.2.10 (<dfn title="1.3.0, 1.3.1, 1.3.11, 1.3.12, 1.3.14, 1.3.17, 1.3.19, 1.3.2, 1.3.20, 1.3.22, 1.3.23, 1.3.24, 1.3.27, 1.3.28, 1.3.29, 1.3.3, 1.3.31, 1.3.32, 1.3.33, 1.3.34, 1.3.35, 1.3.36, 1.3.37, 1.3.39, 1.3.4, 1.3.41, 1.3.6, 1.3.9, 2.0.35, 2.0.36, 2.0.39, 2.0.40, 2.0.42, 2.0.43, 2.0.44, 2.0.45, 2.0.46, 2.0.47, 2.0.48, 2.0.49, 2.0.50, 2.0.51, 2.0.52, 2.0.53, 2.0.54, 2.0.55, 2.0.58, 2.0.59, 2.0.61, 2.0.63, 2.1.3-beta, 2.1.6-alpha, 2.1.7-beta, 2.1.8-beta, 2.1.9-beta, 2.2.0, 2.2.2, 2.2.3, 2.2.4, 2.2.6, 2.2.8, 2.2.9, 2.2.10">all 63 Apache versions</dfn>!), then I <strong>configured and compiled each version for a custom HTTPD installation built from source</strong>. This allowed me to find <strong><a href="#Htaccess_Directives-s0">every directive allowed in .htaccess files</a> and <a href="#Htaccess_Variables">every variable in .htaccess files</a></strong> for each particular version, which has never been done before, or since. <strong>YES!</strong> <em>I think that is so cool..</em>
  101.  
  102. <strong>An .htaccess directive</strong> 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 <strong>apply to the directory they are in, and all sub-directories</strong>.  Here's the 3 top links (<em>official Apache Docs</em>) you will repeatedly use, bookmark/print/save them.
  103.  
  104. <a href="https://www.askapache.com/s/u.askapache.com/2008/08/htaccess-up1.png"><img src="https://www.askapache.com/s/u.askapache.com/2008/08/htaccess-up1-350x178.png" alt="htaccess Context Legend" title="htaccess-up1" width="350" height="178"></a>
  105. <ol>
  106. <li><a href="http://httpd.apache.org/docs/trunk/mod/directive-dict.html">Terms Used to Describe Directives</a></li>
  107. <li><a href="http://httpd.apache.org/docs/trunk/mod/directives.html">Official List of Apache Directives</a></li>
  108. <li><a href="http://httpd.apache.org/docs/trunk/mod/quickreference.html">Directive Quick-Reference -- with Context</a></li>
  109. </ol>
  110.  
  111. <hr class="C">
  112.  
  113. <h2>Main Server Config Examples</h2>
  114. Now lets take a look at some htaccess examples to get a feel for the syntax and some general ideas at the capabilities.  Some of the best examples for .htaccess files are included with Apache for <a href="http://httpd.apache.org/docs/trunk/configuring.html">main server config</a> files, so lets take a quick look at a couple of them on our way down to the actual .htaccess examples further down the page (this site has thousands, take your time).  The basic syntax is <strong>a line starting with # is a comment, everything else are directives followed by the directive argument</strong>.
  115.  
  116. <strong><a href="https://www.askapache.com/s/u.askapache.com/2008/08/httpd-multilang-errordocconf.in">httpd-multilang-errordoc.conf</a></strong>: The configuration below implements multi-language error documents through content-negotiation
  117.  
  118. Here are the rest of them if you wanna take a look.  (<a href="https://www.askapache.com/s/u.askapache.com/2008/08/httpd-mpmconf.in" title="Server-Pool Management (MPM specific)">httpd-mpm.conf</a>, <a href="https://www.askapache.com/s/u.askapache.com/2008/08/httpd-defaultconf.in" title="This configuration file reflects default settings for Apache HTTP Server">httpd-default.conf</a>, <a href="https://www.askapache.com/s/u.askapache.com/2008/08/httpd-sslconf.in" title="Contains the configuration directives to instruct the server how to serve pages over an https connection">httpd-ssl.conf</a>, <a href="https://www.askapache.com/s/u.askapache.com/2008/08/httpd-infoconf.in" title="Get information about the requests being processed by the server and the configuration of the server">httpd-info.conf</a>, <a href="https://www.askapache.com/s/u.askapache.com/2008/08/httpd-vhostsconf.in" title="If you want to maintain multiple domains/hostnames on your machine">httpd-vhosts.conf</a>, <a href="https://www.askapache.com/s/u.askapache.com/2008/08/httpd-davconf.in" title="Distributed authoring and versioning (WebDAV)">httpd-dav.conf</a>)
  119.  
  120. <hr class="C">
  121.  
  122. <h2>Example .htaccess Code Snippets</h2>
  123. Here are some specific examples, this is the most popular section of this page.  Updated frequently.
  124. <h4>Redirect Everyone Except IP address to alternate page</h4>
  125. <pre class="prettyprint lang-config">ErrorDocument 403 http://www.yahoo.com/
  126. Order deny,allow
  127. Deny from all
  128. Allow from 208.113.134.190</pre>
  129. <h4>When developing sites</h4>
  130. This lets google crawl the page, lets me access  without a password, and lets my client access the page WITH a password.  It also allows for XHTML and CSS validation! (w3.org)
  131. <pre class="prettyprint lang-config">AuthName "Under Development"
  132. AuthUserFile /web/sitename.com/.htpasswd
  133. AuthType basic
  134. Require valid-user
  135. Order deny,allow
  136. Deny from all
  137. Allow from 208.113.134.190 w3.org htmlhelp.com googlebot.com
  138. Satisfy Any</pre>
  139. <h4>Fix double-login prompt</h4>
  140. Redirect non-https requests to https server and ensure that <strong>.htpasswd authorization</strong> can only be entered across HTTPS
  141. <pre class="prettyprint lang-config">SSLOptions +StrictRequire
  142. SSLRequireSSL
  143. SSLRequire %{HTTP_HOST} eq "askapache.com"
  144. ErrorDocument 403 https://askapache.com</pre>
  145. <h4>Set Timezone of the Server (GMT)</h4>
  146. <pre class="prettyprint lang-config">SetEnv TZ America/Indianapolis</pre>
  147. <h4>Administrator Email for ErrorDocument</h4>
  148. <pre class="prettyprint lang-config">SetEnv SERVER_ADMIN [email protected]</pre>
  149. <h4><code>ServerSignature</code> for <code>ErrorDocument</code></h4>
  150. <pre class="prettyprint lang-config">ServerSignature off | on | email</pre>
  151. <h4>Charset and Language headers</h4>
  152. Article: <a href="/htaccess/setting-charset-in-htaccess/">Setting Charset in htaccess</a>, and <a href="http://www.w3.org/International/questions/qa-htaccess-charset">article by <cite>Richard Ishida</cite></a>
  153. <pre class="prettyprint lang-config">AddDefaultCharset UTF-8
  154. DefaultLanguage en-US</pre>
  155. <h4>Disallow Script Execution</h4>
  156. <pre class="prettyprint lang-config">Options -ExecCGI
  157. AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi</pre>
  158. <h4>Deny Request Methods</h4>
  159. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|OPTIONS|POST|PUT)
  160. RewriteRule .? - [F]</pre>
  161. <h4>Force "File Save As" Prompt</h4>
  162. <pre class="prettyprint lang-config">AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4</pre>
  163. <h4>Show CGI Source Code</h4>
  164. <pre class="prettyprint lang-config">RemoveHandler cgi-script .pl .py .cgi
  165. AddType text/plain .pl .py .cgi</pre>
  166. <h4>Serve all .pdf files on your site using .htaccess and mod_rewrite with the php script.</h4>
  167. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_FILENAME} -f
  168. RewriteRule ^(.+)\.pdf$  /cgi-bin/pdf.php?file=$1 [L,NC,QSA]</pre>
  169. <h4>Rewrite to www</h4>
  170. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_URI} !^/(robots\.txt|favicon\.ico|sitemap\.xml)$
  171. RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
  172. RewriteRule ^(.*)$ https://www.askapache.com/$1 [R=301,L]</pre>
  173. <h4>Rewrite to www dynamically</h4>
  174. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_URI} !^/robots\.txt$ [NC]
  175. RewriteCond %{HTTP_HOST} !^www\.[a-z-]+\.[a-z]{2,6} [NC]
  176. RewriteCond %{HTTP_HOST} ([a-z-]+\.[a-z]{2,6})$   [NC]
  177. RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]</pre>
  178. <h4>301 Redirect Old File</h4>
  179. <pre class="prettyprint lang-config">Redirect 301 /old/file.html https://www.askapache.com/new/file/</pre>
  180. <h4>301 Redirect Entire Directory</h4>
  181. <pre class="prettyprint lang-config">RedirectMatch 301 /blog(.*) https://www.askapache.com/$1</pre>
  182. <h4>Protecting your php.cgi</h4>
  183. <pre class="prettyprint lang-config">&lt;FilesMatch "^php5?\.(ini|cgi)$"&gt;
  184. Order Deny,Allow
  185. Deny from All
  186. Allow from env=REDIRECT_STATUS
  187. &lt;/FilesMatch&gt;</pre>
  188. <h4>Set Cookie based on Request</h4>
  189. This code sends the <code>Set-Cookie</code> header to create a cookie on the client with the value of a matching item in 2nd parantheses.
  190. <pre class="prettyprint lang-config">RewriteRule ^(.*)(de|es|fr|it|ja|ru|en)/$ - [co=lang:$2:.askapache.com:7200:/]</pre>
  191. <h4>Set Cookie with env variable</h4>
  192. <pre class="prettyprint lang-config">Header set Set-Cookie "language=%{lang}e; path=/;" env=lang</pre>
  193. <h4>Custom ErrorDocuments</h4>
  194. <pre class="prettyprint lang-config">ErrorDocument 100 /100_CONTINUE
  195. ErrorDocument 101 /101_SWITCHING_PROTOCOLS
  196. ErrorDocument 102 /102_PROCESSING
  197. ErrorDocument 200 /200_OK
  198. ErrorDocument 201 /201_CREATED
  199. ErrorDocument 202 /202_ACCEPTED
  200. ErrorDocument 203 /203_NON_AUTHORITATIVE
  201. ErrorDocument 204 /204_NO_CONTENT
  202. ErrorDocument 205 /205_RESET_CONTENT
  203. ErrorDocument 206 /206_PARTIAL_CONTENT
  204. ErrorDocument 207 /207_MULTI_STATUS
  205. ErrorDocument 300 /300_MULTIPLE_CHOICES
  206. ErrorDocument 301 /301_MOVED_PERMANENTLY
  207. ErrorDocument 302 /302_MOVED_TEMPORARILY
  208. ErrorDocument 303 /303_SEE_OTHER
  209. ErrorDocument 304 /304_NOT_MODIFIED
  210. ErrorDocument 305 /305_USE_PROXY
  211. ErrorDocument 307 /307_TEMPORARY_REDIRECT
  212. ErrorDocument 400 /400_BAD_REQUEST
  213. ErrorDocument 401 /401_UNAUTHORIZED
  214. ErrorDocument 402 /402_PAYMENT_REQUIRED
  215. ErrorDocument 403 /403_FORBIDDEN
  216. ErrorDocument 404 /404_NOT_FOUND
  217.  
  218. ErrorDocument 405 /405_METHOD_NOT_ALLOWED
  219. ErrorDocument 406 /406_NOT_ACCEPTABLE
  220. ErrorDocument 407 /407_PROXY_AUTHENTICATION_REQUIRED
  221. ErrorDocument 408 /408_REQUEST_TIME_OUT
  222. ErrorDocument 409 /409_CONFLICT
  223. ErrorDocument 410 /410_GONE
  224. ErrorDocument 411 /411_LENGTH_REQUIRED
  225. ErrorDocument 412 /412_PRECONDITION_FAILED
  226. ErrorDocument 413 /413_REQUEST_ENTITY_TOO_LARGE
  227. ErrorDocument 414 /414_REQUEST_URI_TOO_LARGE
  228. ErrorDocument 415 /415_UNSUPPORTED_MEDIA_TYPE
  229. ErrorDocument 416 /416_RANGE_NOT_SATISFIABLE
  230. ErrorDocument 417 /417_EXPECTATION_FAILED
  231. ErrorDocument 422 /422_UNPROCESSABLE_ENTITY
  232. ErrorDocument 423 /423_LOCKED
  233. ErrorDocument 424 /424_FAILED_DEPENDENCY
  234. ErrorDocument 426 /426_UPGRADE_REQUIRED
  235. ErrorDocument 500 /500_INTERNAL_SERVER_ERROR
  236. ErrorDocument 501 /501_NOT_IMPLEMENTED
  237. ErrorDocument 502 /502_BAD_GATEWAY
  238. ErrorDocument 503 /503_SERVICE_UNAVAILABLE
  239. ErrorDocument 504 /504_GATEWAY_TIME_OUT
  240. ErrorDocument 505 /505_VERSION_NOT_SUPPORTED
  241. ErrorDocument 506 /506_VARIANT_ALSO_VARIES
  242. ErrorDocument 507 /507_INSUFFICIENT_STORAGE
  243. ErrorDocument 510 /510_NOT_EXTENDED</pre>
  244. <h4>Implementing a Caching Scheme with .htaccess</h4>
  245. <pre class="prettyprint lang-config"># year
  246. &lt;FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$"&gt;
  247. Header set Cache-Control "public"
  248. Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
  249. Header unset Last-Modified
  250. &lt;/FilesMatch&gt;
  251. #2 hours
  252. &lt;FilesMatch "\.(html|htm|xml|txt|xsl)$"&gt;
  253. Header set Cache-Control "max-age=7200, must-revalidate"
  254. &lt;/FilesMatch&gt;
  255. &lt;FilesMatch "\.(js|css)$"&gt;
  256. SetOutputFilter DEFLATE
  257. Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
  258. &lt;/FilesMatch&gt;</pre>
  259. <h4>Password Protect single file</h4>
  260. <pre class="prettyprint lang-config">&lt;Files login.php&gt;
  261. AuthName "Prompt"
  262. AuthType Basic
  263. AuthUserFile /web/askapache.com/.htpasswd
  264. Require valid-user
  265. &lt;/Files&gt;</pre>
  266. <h4>Password Protect multiple files</h4>
  267. <pre class="prettyprint lang-config">&lt;FilesMatch "^(private|phpinfo).*$"&gt;
  268. AuthName "Development"
  269. AuthUserFile /.htpasswd
  270. AuthType basic
  271. Require valid-user
  272. &lt;/FilesMatch&gt;</pre>
  273. <h4>Send Custom Headers</h4>
  274. <pre class="prettyprint lang-config">Header set P3P "policyref="https://www.askapache.com/w3c/p3p.xml""
  275. Header set X-Pingback "https://www.askapache.com/xmlrpc.php"
  276. Header set Content-Language "en-US"
  277. Header set Vary "Accept-Encoding"</pre>
  278. <h4>Blocking based on User-Agent Header</h4>
  279. <pre class="prettyprint lang-config">SetEnvIfNoCase ^User-Agent$ .*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures) HTTP_SAFE_BADBOT
  280. SetEnvIfNoCase ^User-Agent$ .*(libwww-perl|aesop_com_spiderman) HTTP_SAFE_BADBOT
  281. Deny from env=HTTP_SAFE_BADBOT</pre>
  282. <h4>Blocking with RewriteCond</h4>
  283. <pre class="prettyprint lang-config">RewriteCond %{HTTP_USER_AGENT} ^.*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures).*$ [NC]
  284. RewriteRule . - [F,L]</pre>
  285. <h4>.htaccess for mod_php</h4>
  286. <pre class="prettyprint lang-config">SetEnv PHPRC /location/todir/containing/phpinifile</pre>
  287. <h4>.htaccess for php as cgi</h4>
  288. <pre class="prettyprint lang-config">AddHandler php-cgi .php .htm
  289. Action php-cgi /cgi-bin/php5.cgi</pre>
  290. <h4>Shell wrapper for custom php.ini</h4>
  291. <pre>#!/bin/sh
  292. export PHP_FCGI_CHILDREN=3
  293. exec php5.cgi -c /abs/php5/php.ini</pre>
  294. <h4>Add values from HTTP Headers</h4>
  295. <pre class="prettyprint lang-config">SetEnvIfNoCase ^If-Modified-Since$ "(.+)" HTTP_IF_MODIFIED_SINCE=$1
  296. SetEnvIfNoCase ^If-None-Match$ "(.+)" HTTP_IF_NONE_MATCH=$1
  297. SetEnvIfNoCase ^Cache-Control$ "(.+)" HTTP_CACHE_CONTROL=$1
  298. SetEnvIfNoCase ^Connection$ "(.+)" HTTP_CONNECTION=$1
  299. SetEnvIfNoCase ^Keep-Alive$ "(.+)" HTTP_KEEP_ALIVE=$1
  300. SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
  301. SetEnvIfNoCase ^Cookie$ "(.+)" HTTP_MY_COOKIE=$1</pre>
  302. <h4>Stop hotlinking</h4>
  303. <pre class="prettyprint lang-config">RewriteCond %{HTTP_REFERER} !^$
  304. RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache\.com/.*$ [NC]
  305. RewriteRule \.(gif|jpg|swf|flv|png)$ https://www.askapache.com/feed.gif [R=302,L]</pre>
  306. <h2>Example .htaccess Files</h2>
  307. Here are some samples and examples taken from different .htaccess files I've used over the years.  Specific solutions are farther down on this page and throughout the site.
  308. <pre class="prettyprint lang-config"># Set the Time Zone of your Server
  309. SetEnv TZ America/Indianapolis
  310.  
  311. # ServerAdmin:  This address appears on some server-generated pages, such as error documents.
  312. SetEnv SERVER_ADMIN [email protected]
  313.  
  314. # Possible values for the Options directive are "None", "All", or any combination of:
  315. #  Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
  316. Options -ExecCGI -MultiViews -Includes -Indexes FollowSymLinks
  317.  
  318. # DirectoryIndex: sets the file that Apache will serve if a directory is requested.
  319. DirectoryIndex index.html index.php /index.php
  320.  
  321. # Action lets you define media types that will execute a script whenever
  322. # a matching file is called. This eliminates the need for repeated URL
  323. # pathnames for oft-used CGI file processors.
  324. # Format: Action media/type /cgi-script/location
  325. # Format: Action handler-name /cgi-script/location
  326. #
  327. Action php5-cgi /bin/php.cgi
  328.  
  329. # AddHandler allows you to map certain file extensions to "handlers":
  330. # actions unrelated to filetype. These can be either built into the server
  331. # or added with the Action directive (see below)
  332. #
  333. # To use CGI scripts outside of ScriptAliased directories:
  334. # (You will also need to add "ExecCGI" to the "Options" directive.)
  335. #
  336. AddHandler php-cgi .php .inc
  337.  
  338. # Commonly used filename extensions to character sets.
  339. AddDefaultCharset UTF-8
  340.  
  341. # AddType allows you to add to or override the MIME configuration
  342. AddType &#039;application/rdf+xml; charset=UTF-8&#039; .rdf
  343. AddType &#039;application/xhtml+xml; charset=UTF-8&#039; .xhtml
  344. AddType &#039;application/xhtml+xml; charset=UTF-8&#039; .xhtml.gz
  345. AddType &#039;text/html; charset=UTF-8&#039; .html
  346. AddType &#039;text/html; charset=UTF-8&#039; .html.gz
  347. AddType application/octet-stream .rar .chm .bz2 .tgz .msi .pdf .exe
  348. AddType application/vnd.ms-excel .csv
  349. AddType application/x-httpd-php-source .phps
  350. AddType application/x-pilot .prc .pdb
  351. AddType application/x-shockwave-flash .swf
  352. AddType application/xrds+xml .xrdf
  353. AddType text/plain .ini .sh .bsh .bash .awk .nawk .gawk .csh .var .c .in .h .asc .md5 .sha .sha1
  354. AddType video/x-flv .flv
  355.  
  356. # AddEncoding allows you to have certain browsers uncompress information on the fly. Note: Not all browsers support this.
  357. AddEncoding x-compress .Z
  358. AddEncoding x-gzip .gz .tgz
  359.  
  360. # DefaultType: the default MIME type the server will use for a document.
  361. DefaultType text/html
  362.  
  363. # Optionally add a line containing the server version and virtual host
  364. # name to server-generated pages (internal error documents, FTP directory
  365. # listings, mod_status and mod_info output etc., but not CGI generated
  366. # documents or custom error documents).
  367. # Set to "EMail" to also include a mailto: link to the ServerAdmin.
  368. # Set to one of:  On | Off | EMail
  369. ServerSignature Off</pre>
  370. <pre class="prettyprint lang-config">## MAIN DEFAULTS
  371. Options +ExecCGI -Indexes
  372. DirectoryIndex index.html index.htm index.php
  373. DefaultLanguage en-US
  374. AddDefaultCharset UTF-8
  375. ServerSignature Off
  376.  
  377. ## ENVIRONMENT VARIABLES
  378. SetEnv PHPRC /webroot/includes
  379. SetEnv TZ America/Indianapolis
  380.  
  381. SetEnv SERVER_ADMIN [email protected]
  382.  
  383. ## MIME TYPES
  384. AddType video/x-flv .flv
  385. AddType application/x-shockwave-flash .swf
  386. AddType image/x-icon .ico
  387.  
  388. ## FORCE FILE TO DOWNLOAD INSTEAD OF APPEAR IN BROWSER
  389. # http://www.htaccesselite.com/addtype-addhandler-action-vf6.html
  390. AddType application/octet-stream .mov .mp3 .zip
  391.  
  392. ## ERRORDOCUMENTS
  393. # http://askapache.com/htaccess/apache-status-code-headers-errordocument.html
  394. ErrorDocument 400 /e400/
  395. ErrorDocument 401 /e401/
  396. ErrorDocument 402 /e402/
  397. ErrorDocument 403 /e403/
  398. ErrorDocument 404 /e404/
  399.  
  400. # Handlers be builtin, included in a module, or added with Action directive
  401. # default-handler: default, handles static content (core)
  402. #   send-as-is: Send file with HTTP headers (mod_asis)
  403. #   cgi-script: treat file as CGI script (mod_cgi)
  404. #    imap-file: Parse as an imagemap rule file (mod_imap)
  405. #   server-info: Get server config info (mod_info)
  406. #  server-status: Get server status report (mod_status)
  407. #    type-map: type map file for content negotiation (mod_negotiation)
  408. #  fastcgi-script: treat file as fastcgi script (mod_fastcgi)
  409. #
  410. # https://www.askapache.com/php/custom-phpini-tips-and-tricks/
  411.  
  412. ## PARSE AS CGI
  413. AddHandler cgi-script .cgi .pl .spl
  414.  
  415. ## RUN PHP AS APACHE MODULE
  416. AddHandler application/x-httpd-php .php .htm
  417.  
  418. ## RUN PHP AS CGI
  419. AddHandler php-cgi .php .htm
  420.  
  421. ## CGI PHP WRAPPER FOR CUSTOM PHP.INI
  422. AddHandler phpini-cgi .php .htm
  423. Action phpini-cgi /cgi-bin/php5-custom-ini.cgi
  424.  
  425. ## FAST-CGI SETUP WITH PHP-CGI WRAPPER FOR CUSTOM PHP.INI
  426. AddHandler fastcgi-script .fcgi
  427. AddHandler php-cgi .php .htm
  428. Action php-cgi /cgi-bin/php5-wrapper.fcgi
  429.  
  430. ## CUSTOM PHP CGI BINARY SETUP
  431. AddHandler php-cgi .php .htm
  432. Action php-cgi /cgi-bin/php.cgi
  433.  
  434. ## PROCESS SPECIFIC FILETYPES WITH CGI-SCRIPT
  435. Action image/gif /cgi-bin/img-create.cgi
  436.  
  437. ## CREATE CUSTOM HANDLER FOR SPECIFIC FILE EXTENSIONS
  438. AddHandler custom-processor .ssp
  439. Action custom-processor /cgi-bin/myprocessor.cgi
  440.  
  441. ### HEADER CACHING
  442. # https://www.askapache.com/htaccess/speed-up-sites-with-htaccess-caching/
  443. &lt;FilesMatch "\.(flv|gif|jpg|jpeg|png|ico)$"&gt;
  444. Header set Cache-Control "max-age=2592000"
  445. &lt;/FilesMatch&gt;
  446. &lt;FilesMatch "\.(js|css|pdf|swf)$"&gt;
  447. Header set Cache-Control "max-age=604800"
  448. &lt;/FilesMatch&gt;
  449. &lt;FilesMatch "\.(html|htm|txt)$"&gt;
  450. Header set Cache-Control "max-age=600"
  451. &lt;/FilesMatch&gt;
  452. &lt;FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"&gt;
  453. Header unset Cache-Control
  454. &lt;/FilesMatch&gt;
  455.  
  456. ## ALTERNATE EXPIRES CACHING
  457. # htaccesselite.com/d/use-htaccess-to-speed-up-your-site-discussion-vt67.html
  458. ExpiresActive On
  459. ExpiresDefault A604800
  460. ExpiresByType image/x-icon A2592000
  461. ExpiresByType application/x-javascript A2592000
  462. ExpiresByType text/css A2592000
  463. ExpiresByType text/html A300
  464.  
  465. &lt;FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"&gt;
  466. ExpiresActive Off
  467. &lt;/FilesMatch&gt;
  468.  
  469. ## META HTTP-EQUIV REPLACEMENTS
  470. &lt;FilesMatch "\.(html|htm|php)$"&gt;
  471. Header set imagetoolbar "no"
  472. &lt;/FilesMatch&gt;</pre>
  473. Here are some default MOD_REWRITE code examples.
  474. <pre class="prettyprint lang-config">## REWRITE DEFAULTS
  475. RewriteEngine On
  476. RewriteBase /
  477.  
  478. ## REQUIRE SUBDOMAIN
  479. RewriteCond %{HTTP_HOST} !^$
  480. RewriteCond %{HTTP_HOST} !^subdomain\.askapache\.com$ [NC]
  481. RewriteRule ^/(.*)$ http://subdomain.askapache.com/$1 [L,R=301]
  482.  
  483. ## SEO REWRITES
  484. RewriteRule ^(.*)/ve/(.*)$ $1/voluntary-employee/$2 [L,R=301]
  485. RewriteRule ^(.*)/hsa/(.*)$ $1/health-saving-account/$2 [L,R=301]
  486.  
  487. ## WORDPRESS
  488. RewriteCond %{REQUEST_FILENAME} !-f  # Existing File
  489. RewriteCond %{REQUEST_FILENAME} !-d  # Existing Directory
  490. RewriteRule . /index.php [L]
  491.  
  492. ## ALTERNATIVE ANTI-HOTLINKING
  493. RewriteCond %{HTTP_REFERER} !^$
  494. RewriteCond %{HTTP_REFERER} !^http://(subdomain\.)?askapache\.com/.*$ [NC]
  495. RewriteRule ^.*\.(bmp|tif|gif|jpg|jpeg|jpe|png)$ - [F]
  496.  
  497. ## REDIRECT HOTLINKERS
  498. RewriteCond %{HTTP_REFERER} !^$
  499. RewriteCond %{HTTP_REFERER} !^http://(subdomain\.)?askapache\.com/.*$ [NC]
  500. RewriteRule ^.*\.(bmp|tif|gif|jpg|jpeg|jpe|png)$ http://google.com [R]
  501.  
  502. ## DENY REQUEST BASED ON REQUEST METHOD
  503. RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS|HEAD)$ [NC]
  504. RewriteRule ^.*$ - [F]
  505.  
  506. ## REDIRECT UPLOADS
  507. RewriteCond %{REQUEST_METHOD} ^(PUT|POST)$ [NC]
  508. RewriteRule ^(.*)$ /cgi-bin/form-upload-processor.cgi?p=$1 [L,QSA]
  509.  
  510. ## REQUIRE SSL EVEN WHEN MOD_SSL IS NOT LOADED
  511. RewriteCond %{HTTPS} !=on [NC]
  512. RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
  513.  
  514. ### ALTERNATATIVE TO USING ERRORDOCUMENT
  515. # http://www.htaccesselite.com/d/htaccess-errordocument-examples-vt11.html
  516. RewriteCond %{REQUEST_FILENAME} !-f
  517. RewriteCond %{REQUEST_FILENAME} !-d
  518. RewriteRule ^.*$ /error.php [L]
  519.  
  520. ## SEO REDIRECTS
  521. Redirect 301 /2006/oldfile.html http://subdomain.askapache.com/newfile.html
  522. RedirectMatch 301 /o/(.*)$ http://subdomain.askapache.com/s/dl/$1</pre>
  523. Examples of protecting your files and securing with password protection.
  524. <pre class="prettyprint lang-config">#
  525. # Require (user|group|valid-user) (username|groupname)
  526. #
  527. ## BASIC PASSWORD PROTECTION
  528. AuthType basic
  529. AuthName "prompt"
  530. AuthUserFile /.htpasswd
  531. AuthGroupFile /dev/null
  532. Require valid-user
  533.  
  534. ## ALLOW FROM IP OR VALID PASSWORD
  535. Require valid-user
  536. Allow from 192.168.1.23
  537. Satisfy Any
  538.  
  539. ## PROTECT FILES
  540. &lt;FilesMatch "\.(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$"&gt;
  541. Order Allow,Deny
  542. Deny from all
  543. &lt;/FilesMatch&gt;
  544.  
  545. ## PREVENT HOTLINKING
  546. SetEnvIfNoCase Referer "^http://subdomain.askapache.com/" good
  547. SetEnvIfNoCase Referer "^$" good
  548. &lt;FilesMatch "\.(png|jpg|jpeg|gif|bmp|swf|flv)$"&gt;
  549. Order Deny,Allow
  550. Deny from all
  551. Allow from env=good
  552. ErrorDocument 403 http://www.google.com/intl/en_ALL/images/logo.gif
  553. ErrorDocument 403 /images/you_bad_hotlinker.gif
  554. &lt;/FilesMatch&gt;
  555.  
  556. ## LIMIT UPLOAD FILE SIZE TO PROTECT AGAINST DOS ATTACK
  557. #bytes, 0-2147483647(2GB)
  558. LimitRequestBody 10240000
  559.  
  560. ## MOST SECURE WAY TO REQUIRE SSL
  561. # https://www.askapache.com/htaccess/apache-ssl-in-htaccess-examples/
  562. SSLOptions +StrictRequire
  563. SSLRequireSSL
  564. SSLRequire %{HTTP_HOST} eq "askapache.com"
  565. ErrorDocument 403 https://askapache.com
  566.  
  567. ## COMBINED DEVELOPER HTACCESS CODE-USE THIS
  568. &lt;FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|js|css|pdf|swf|html|htm|txt)$"&gt;
  569. Header set Cache-Control "max-age=5"
  570. &lt;/FilesMatch&gt;
  571. AuthType basic
  572. AuthName "Ooops! Temporarily Under Construction..."
  573. AuthUserFile /.htpasswd
  574. AuthGroupFile /dev/null
  575. Require valid-user      # password prompt for everyone else
  576. Order Deny,Allow
  577. Deny from all
  578. Allow from 192.168.64.5   # Your, the developers IP address
  579. Allow from w3.org      # css/xhtml check jigsaw.w3.org/css-validator/
  580. Allow from googlebot.com   # Allows google to crawl your pages
  581. Satisfy Any        # no password required if host/ip is Allowed
  582.  
  583. ## DONT HAVE TO EMPTY CACHE OR RELOAD TO SEE CHANGES
  584. ExpiresDefault A5 #If using mod_expires
  585. &lt;FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|js|css|pdf|swf|html|htm|txt)$"&gt;
  586. Header set Cache-Control "max-age=5"
  587. &lt;/FilesMatch&gt;
  588.  
  589. ## ALLOW ACCESS WITH PASSWORD OR NO PASSWORD FOR SPECIFIC IP/HOSTS
  590. AuthType basic
  591. AuthName "Ooops! Temporarily Under Construction..."
  592. AuthUserFile /.htpasswd
  593. AuthGroupFile /dev/null
  594. Require valid-user      # password prompt for everyone else
  595. Order Deny,Allow
  596. Deny from all
  597. Allow from 192.168.64.5   # Your, the developers IP address
  598. Allow from w3.org      # css/xhtml check jigsaw.w3.org/css-validator/
  599. Allow from googlebot.com   # Allows google to crawl your pages
  600. Satisfy Any        # no password required if host/ip is Allowed</pre>
  601. <h2>Advanced Mod_Rewrites</h2>
  602. Here are some <a href="https://www.askapache.com/htaccess/" title="Htaccess Tutorial">specific htaccess</a> examples taken mostly from my WordPress Password Protection plugin, which does alot more than password protection as you will see from the following mod_rewrite examples. These are a few of the mod_rewrite uses that BlogSecurity declared <strong>pushed the boundaries of Mod_Rewrite!</strong>  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.
  603. <h3>Directory Protection</h3>
  604. Enable the DirectoryIndex Protection, preventing directory index listings and defaulting. [<a href="/htaccess/">Disable</a>]
  605. <pre class="prettyprint lang-config">Options -Indexes
  606. DirectoryIndex index.html index.php /index.php</pre>
  607. <h3>Password Protect wp-login.php</h3>
  608. Requires a valid user/pass to access the login page[<a href="/htaccess/apache-status-code-headers-errordocument/#status-401">401</a>]
  609. <pre class="prettyprint lang-config">&lt;Files wp-login.php&gt;
  610. Order Deny,Allow
  611. Deny from All
  612. Satisfy Any
  613. AuthName "Protected By AskApache"
  614. AuthUserFile /web/askapache.com/.htpasswda1
  615. AuthType Basic
  616. Require valid-user
  617. &lt;/Files&gt;</pre>
  618. <h3>Password Protect wp-admin</h3>
  619. Requires a valid user/pass to access any non-static (css, js, images) file in this directory.[<a href="/htaccess/apache-status-code-headers-errordocument/#status-401">401</a>]
  620. <pre class="prettyprint lang-config">Options -ExecCGI -Indexes +FollowSymLinks -Includes
  621. DirectoryIndex index.php /index.php
  622. Order Deny,Allow
  623. Deny from All
  624. Satisfy Any
  625. AuthName "Protected By AskApache"
  626. AuthUserFile /web/askapache.com/.htpasswda1
  627. AuthType Basic
  628. Require valid-user
  629. &lt;FilesMatch "\.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$"&gt;
  630. Allow from All
  631. &lt;/FilesMatch&gt;
  632. &lt;FilesMatch "(async-upload)\.php$"&gt;
  633. &lt;IfModule mod_security.c&gt;
  634. SecFilterEngine Off
  635. &lt;/IfModule&gt;
  636. Allow from All
  637. &lt;/FilesMatch&gt;</pre>
  638. <h3>Protect wp-content</h3>
  639. Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="/htaccess/apache-status-code-headers-errordocument/#status-401">401</a>]
  640. <pre class="prettyprint lang-config">RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-content/.*$ [NC]
  641. RewriteCond %{REQUEST_FILENAME} !^.+flexible-upload-wp25js.php$
  642. RewriteCond %{REQUEST_FILENAME} ^.+\.(php|html|htm|txt)$
  643. RewriteRule .? - [F,NS,L]</pre>
  644. <h3>Protect wp-includes</h3>
  645. Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  646. <pre class="prettyprint lang-config">RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-includes/.*$ [NC]
  647. RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /wp-includes/js/.+/.+\ HTTP/ [NC]
  648. RewriteCond %{REQUEST_FILENAME} ^.+\.php$
  649. RewriteRule .? - [F,NS,L]</pre>
  650. <h3>Common Exploits</h3>
  651. Block common exploit requests with 403 Forbidden. These can help alot, may break some plugins. [<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  652. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
  653. RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ ///.*\ HTTP/ [NC,OR]
  654. RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\=?(http|ftp|ssl|https):/.*\ HTTP/ [NC,OR]
  655. RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\?.*\ HTTP/ [NC,OR]
  656. RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(asp|ini|dll).*\ HTTP/ [NC,OR]
  657. RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(htpasswd|htaccess|aahtpasswd).*\ HTTP/ [NC]
  658. RewriteRule .? - [F,NS,L]</pre>
  659. <h3>Stop Hotlinking</h3>
  660. Denies any request for static files (images, css, etc) if referrer is not local site or empty. [<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  661. <pre class="prettyprint lang-config">RewriteCond %{HTTP_REFERER} !^$
  662. RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
  663. RewriteCond %{HTTP_REFERER} !^https://www.askapache.com.*$ [NC]
  664. RewriteRule \.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$ - [F,NS,L]</pre>
  665. <h3>Safe Request Methods</h3>
  666. Denies any request not using <a href="https://www.askapache.com/online-tools/request-method-scanner/">GET,PROPFIND,POST,OPTIONS,PUT,HEAD</a>[<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  667. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|POST|PROPFIND|OPTIONS|PUT)$ [NC]
  668. RewriteRule .? - [F,NS,L]</pre>
  669. <h3>Forbid Proxies</h3>
  670. Denies any POST Request using a Proxy Server. Can still access site, but not comment.  See <a href="http://perishablepress.com/press/2008/04/20/how-to-block-proxy-servers-via-htaccess/">Perishable Press</a> [<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  671. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_METHOD} =POST
  672. RewriteCond %{HTTP:VIA}%{HTTP:FORWARDED}%{HTTP:USERAGENT_VIA}%{HTTP:X_FORWARDED_FOR}%{HTTP:PROXY_CONNECTION} !^$ [OR]
  673. RewriteCond %{HTTP:XPROXY_CONNECTION}%{HTTP:HTTP_PC_REMOTE_ADDR}%{HTTP:HTTP_CLIENT_IP} !^$
  674. RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
  675. RewriteRule .? - [F,NS,L]</pre>
  676. <h3>Real wp-comments-post.php</h3>
  677. Denies any POST attempt made to a non-existing wp-comments-post.php[<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  678. <pre class="prettyprint lang-config">RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
  679. RewriteRule .? - [F,NS,L]</pre>
  680. <h3>HTTP PROTOCOL</h3>
  681. Denies any badly formed HTTP PROTOCOL in the request, 0.9, 1.0, and 1.1 only[<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  682. <pre class="prettyprint lang-config">RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ .+\ HTTP/(0\.9|1\.0|1\.1) [NC]
  683. RewriteRule .? - [F,NS,L]</pre>
  684. <h3>SPECIFY CHARACTERS</h3>
  685. Denies any request for a url containing characters other than "a-zA-Z0-9.+/-?=&amp;"  - REALLY helps but may break your site depending on your links. [<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  686. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
  687. RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/ [NC]
  688. RewriteRule .? - [F,NS,L]</pre>
  689. <h3>BAD Content Length</h3>
  690. Denies any POST request that doesnt have a Content-Length Header[<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  691. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_METHOD} =POST
  692. RewriteCond %{HTTP:Content-Length} ^$
  693. RewriteCond %{REQUEST_URI} !^/(wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
  694. RewriteRule .? - [F,NS,L]</pre>
  695. <h3>BAD Content Type</h3>
  696. Denies any POST request with a content type other than application/x-www-form-urlencoded|multipart/form-data[<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  697. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_METHOD} =POST
  698. RewriteCond %{HTTP:Content-Type} !^(application/x-www-form-urlencoded|multipart/form-data.*(boundary.*)?)$ [NC]
  699. RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
  700. RewriteRule .? - [F,NS,L]</pre>
  701. <h3>Missing HTTP_HOST</h3>
  702. Denies requests that dont contain a HTTP HOST Header.[<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  703. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
  704. RewriteCond %{HTTP_HOST} ^$
  705. RewriteRule .? - [F,NS,L]</pre>
  706. <h3>Bogus Graphics Exploit</h3>
  707. Denies obvious exploit using bogus graphics[<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  708. <pre class="prettyprint lang-config">RewriteCond %{HTTP:Content-Disposition} \.php [NC]
  709. RewriteCond %{HTTP:Content-Type} image/.+ [NC]
  710. RewriteRule .? - [F,NS,L]</pre>
  711. <h3>No UserAgent, Not POST</h3>
  712. Denies POST requests by blank user-agents.  May prevent a small number of visitors from POSTING. [<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  713. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_METHOD} =POST
  714. RewriteCond %{HTTP_USER_AGENT} ^-?$
  715. RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
  716. RewriteRule .? - [F,NS,L]</pre>
  717. <h3>No Referer, No Comment</h3>
  718. Denies any comment attempt with a blank HTTP_REFERER field, highly indicative of spam.  May prevent some visitors from POSTING. [<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  719. <pre class="prettyprint lang-config">RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
  720. RewriteCond %{HTTP_REFERER} ^-?$
  721. RewriteRule .? - [F,NS,L]</pre>
  722. <h3>Trackback Spam</h3>
  723. Denies obvious trackback spam.  See Holy Shmoly! [<a href="/htaccess/apache-status-code-headers-errordocument/#status-403">403</a>]
  724. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_METHOD} =POST
  725. RewriteCond %{HTTP_USER_AGENT} ^.*(opera|mozilla|firefox|msie|safari).*$ [NC]
  726. RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.+/trackback/?\ HTTP/ [NC]
  727. RewriteRule .? - [F,NS,L]</pre>
  728. <h3>Map all URIs except those corresponding to existing files to a handler</h3>
  729. <pre class="prettyprint lang-config">RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
  730. RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
  731. RewriteRule . /script.php</pre>
  732. <h3>Map any request to a handler</h3>
  733. In the case where all URIs should be sent to the same place (including potentially requests for static content) the method to use depends on the type of the handler. For php scripts, use:
  734. For other handlers such as php scripts, use:
  735. <pre class="prettyprint lang-config">RewriteCond %{REQUEST_URI} !=/script.php
  736. RewriteRule .* /script.php</pre>
  737. <h3>And for CGI scripts:</h3>
  738. <pre class="prettyprint lang-config">ScriptAliasMatch .* /var/www/script.cgi</pre>
  739. <h3>Map URIs corresponding to existing files to a handler instead</h3>
  740. <pre class="prettyprint lang-config">RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d [OR]
  741. RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
  742. RewriteCond %{REQUEST_URI} !=/script.php
  743. RewriteRule .* /script.php</pre>
  744. If the existing files you wish to have handled by your script have a common set of file extensions distinct from that of the hander, you can bypass mod_rewrite and use instead mod_actions. Let's say you want all .html and .tpl files to be dealt with by your script:
  745. <pre class="prettyprint lang-config">Action foo-action /script.php
  746. AddHandler foo-action html tpl</pre>
  747. <h3>Deny access if var=val contains the string foo.</h3>
  748. <pre class="prettyprint lang-config">RewriteCond %{QUERY_STRING} foo
  749. RewriteRule ^/url - [F]</pre>
  750. <h3>Removing the Query String</h3>
  751. <pre class="prettyprint lang-config">RewriteRule ^/url /url?</pre>
  752. <h3>Adding to the Query String</h3>
  753. Keep the existing query string using the Query String Append flag, but add var=val to the end.
  754. <pre class="prettyprint lang-config">RewriteRule ^/url /url?var=val [QSA]</pre>
  755. <h3>Rewriting For Certain Query Strings</h3>
  756. Rewrite URLs like http://askapache.com/url1?var=val to http://askapache.com/url2?var=val but don't rewrite if val isn't present.
  757. <pre class="prettyprint lang-config">RewriteCond %{QUERY_STRING} val
  758. RewriteRule ^/url1 /url2</pre>
  759. <h3>Modifying the Query String</h3>
  760. Change any single instance of val in the query string to other_val when accessing /path. Note that %1 and %2 are back-references to the matched part of the regular expression in the previous RewriteCond.
  761. <pre class="prettyprint lang-config">RewriteCond %{QUERY_STRING} ^(.*)val(.*)$
  762. RewriteRule /path /path?%1other_val%2</pre>
  763. <h2>Best .htaccess Articles</h2>
  764. <h3><a title="Apache HTTP Web Server htaccess tips and tricks" rel="chapter" href="https://www.askapache.com/htaccess/htaccess-for-webmasters/">.htaccess for Webmasters</a></h3>
  765. <ul>
  766. <li><a title="htaccess trick to run requests through a cgi script" href="/htaccess/htaccess-for-webmasters/#process-file-through-cgi">Process certain requests for files using a cgi script</a></li>
  767. <li><a title="htaccess security for apache hacking" href="/htaccess/htaccess-for-webmasters/#process-request-methods-with-script">Process Requests with certain Request Methods</a></li>
  768. <li><a title="Apache ForceType Directive in htaccess process file" href="/htaccess/htaccess-for-webmasters/#force-filetype-with-forcetype">Make any file be a certain filetype</a></li>
  769. <li><a title="Using the IfModule Directive in Apache htaccess files." href="/htaccess/htaccess-for-webmasters/#ifmodule-in-apache">Use IfModule directive for robust code</a></li>
  770. </ul>
  771. <h3><a title="mod_rewrite RewriteRule, RewriteCond help" rel="chapter" href="https://www.askapache.com/htaccess/modrewrite-tips-tricks/">Mod_Rewrite URL Rewriting</a></h3>
  772. <a class="hs hs13" href="/htaccess/crazy-advanced-mod_rewrite-tutorial/#decoded"></a>Undocumented techniques and methods will allow you to utilize mod_rewrite at an  "expert level" by showing you how to <a href="/htaccess/crazy-advanced-mod_rewrite-tutorial/#decoded">unlock its secrets</a>.
  773. <ul>
  774. <li><a title="Search query string at QUERY_STRING" href="/htaccess/modrewrite-tips-tricks/#check-for-key-in-query-string">Check for a key in QUERY_STRING</a></li>
  775. <li><a title="Deny access using htaccess during certain time" href="/htaccess/modrewrite-tips-tricks/#time-based-access">Block access to files during certain hours of the day</a></li>
  776. <li><a title="Change underscores to hyphens for SEO URL" href="/htaccess/modrewrite-tips-tricks/#convert-underscore-hyphen">Rewrite underscores to hyphens for SEO URL</a></li>
  777. <li><a title="Rewriting WordPress RSS feeds to Feedburner in SEO friendly method" href="/htaccess/modrewrite-tips-tricks/#redirect-wordpress-feed">Redirecting Wordpress Feeds to Feedburner</a></li>
  778. </ul>
  779. <h3><a title="301 Redirects" rel="chapter" href="https://www.askapache.com/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite/">301 Redirects without mod_rewrite</a></h3>
  780. <ul>
  781. <li><a title="301 Redirect single file" href="/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite/#seo-301-redirect-single-file">Redirect single url</a></li>
  782. <li><a title="301 Redirect new domain" href="/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite/#seo-301-redirect-new-domain">Redirect to new Domain</a></li>
  783. </ul>
  784. <h3><a href="/htaccess/php-cgi-redirect_status/">Secure PHP with .htaccess</a></h3>
  785. <a class="IFL" title="Locking down your php.ini and php cgi with .htaccess" href="/htaccess/php-cgi-redirect_status/"><img src="https://www.askapache.com/s/u.askapache.com/2008/01/jail-bars-1.png" alt="Locking down your php.ini and php cgi with .htaccess"></a>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.<br class="C">
  786. <h3><a href="/htaccess/htaccess-fresh/">.htaccess Cookie Manipulation</a></h3>
  787. <a class="IFL" title="Cookie Manipulation in .htaccess with <a href=" htaccess="" htaccess-fresh="" "=""><img src="https://www.askapache.com/s/u.askapache.com/2007/10/cookies.png" alt="Cookie Manipulation in .htaccess with RewriteRule"></a><strong>Fresh <a href="/htaccess/">.htaccess</a> code</strong> for you!  Check out the Cookie Manipulation and environment variable usage with mod_rewrite!  I also included a couple Mod_Security .htaccess examples. <strong>Enjoy!</strong><br class="C">
  788. <ul>
  789. <li><a href="/htaccess/htaccess-fresh/#modrewrite1">Mod_Rewrite .htaccess Examples</a></li>
  790. <li><a href="/htaccess/htaccess-fresh/#modrewrite2">Cookie Manipulation and Tests with mod_rewrite</a></li>
  791. <li><a href="/htaccess/htaccess-fresh/#modrewrite3">Setting Environment Variables</a></li>
  792. <li><a href="/htaccess/htaccess-fresh/#modrewrite4">Using the Environment Variable</a></li>
  793. <li><a href="/htaccess/htaccess-fresh/#modrewrite5">Mod_Security .htaccess Examples</a></li>
  794. </ul>
  795. <h3><a title="htaccess Caching" rel="chapter" href="https://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control/">.htaccess Caching</a></h3>
  796. <ul>
  797. <li><a href="/htaccess/speed-up-sites-with-htaccess-caching/">Speed Up Sites with htaccess Caching</a></li>
  798. <li><a title="htaccess time cheatsheet" href="/htaccess/speed-up-your-site-with-caching-and-cache-control/#htaccess-time-cheatsheet">htaccess time cheat sheet</a></li>
  799. </ul>
  800. <h3><a title="401, 403 htpasswd authentication" rel="chapter" href="https://www.askapache.com/htaccess/apache-authentication-in-htaccess/">Password Protection and Authentication</a></h3>
  801. <ul>
  802. <li><a title="Requiring a password for single file" href="/htaccess/apache-authentication-in-htaccess/#require-password-for-single-file">Require password for single file</a></li>
  803. <li><a title="A comprehensive default Apache .htaccess example file" href="/htaccess/apache-authentication-in-htaccess/#skeleton-htaccess">Example .htaccess file for password protection</a></li>
  804. </ul>
  805. <h3><a title="Creating and using HTTP Headers with htaccess" rel="chapter" href="https://www.askapache.com/htaccess/using-http-headers-with-htaccess/">Control HTTP Headers</a></h3>
  806. <ul>
  807. <li><a title="Prevent Browsers and Proxies from caching" href="/htaccess/using-http-headers-with-htaccess/#prevent-caching-with-htaccess">Prevent Caching 100%</a></li>
  808. <li><a title="Remove Internet Explorer imagetoolbar" href="/htaccess/using-http-headers-with-htaccess/#remove-ie-imagetoolbar">Remove IE imagetoolbar without meta tag</a></li>
  809. <li><a title="How To use Apache to send P3P Privacy Header for website" href="/htaccess/using-http-headers-with-htaccess/#privacy-p3p-header-in-apache">Add Privacy (P3P) Header to your site</a></li>
  810. <li><a title="Language header, Charset header without meta" href="/htaccess/using-http-headers-with-htaccess/#language-and-content-header-in-htaccess">Add language and charset headers without meta tags</a></li>
  811. </ul>
  812. <h3><a href="/htaccess/blocking-bad-bots-and-scrapers-with-htaccess/">Blocking Spam and bad Bots</a></h3>
  813. <a class="IFR" href="/htaccess/blocking-bad-bots-and-scrapers-with-htaccess/"><img title="Block Bad Robot" src="https://www.askapache.com/s/u.askapache.com/2008/04/bad_robot1.png" alt="Block Bad Robot" height="100"></a>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.<br class="C">
  814. <h3><a title="php htaccess tips, htaccess php tricks" rel="chapter" href="https://www.askapache.com/htaccess/php-htaccess-tips-and-tricks/">PHP htaccess tips</a></h3>
  815. 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
  816. <ul>
  817. <li><a title=".htaccess for php as cgi" href="/htaccess/php-htaccess-tips-and-tricks/#php-run-as-cgi">When php run as CGI</a></li>
  818. <li><a title="custom php.ini with Apache htaccess using PHPRC" href="/htaccess/php-htaccess-tips-and-tricks/#htaccess-php-ini">Use a custom php.ini with mod_php or php as a cgi</a></li>
  819. <li><a title="htaccess tips for mod_php php running as Apache module" href="/htaccess/php-htaccess-tips-and-tricks/#sub-mod_php">When php run as Apache Module (mod_php)</a></li>
  820. <li><a title="Apache FastCGI wrapper for php cgi" href="/htaccess/php-htaccess-tips-and-tricks/#php-and-fastcgi-in-htaccess">When cgi php is run with wrapper (FastCGI)</a></li>
  821. </ul>
  822. <h3><a href="/htaccess/http-https-rewriterule-redirect/">HTTP to HTTPS Redirects with mod_rewrite</a></h3>
  823. <a href="/htaccess/http-https-rewriterule-redirect/"><img class="IFL" src="https://www.askapache.com/s/u.askapache.com/2007/11/security.png" alt="HTTP to HTTPS Redirects with mod_rewrite"></a>This is freaking sweet if you use SSL I promise you!  Basically instead of having to check for HTTPS using a <code>RewriteCond %{HTTPS} =on</code> 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 <a href="http://htaccess.io/directive/rewriterule/">RewriteRule</a><a href="http://htaccess.io/directive/rewriterule/"></a>.<br class="C">
  824. <h3><a title="Apache SSL examples" rel="chapter" href="https://www.askapache.com/htaccess/ssl-example-usage-in-htaccess/">SSL in .htaccess</a></h3>
  825. <ul>
  826. <li><a title="Redirecting non-SSL to SSL in Apache" href="/htaccess/ssl-example-usage-in-htaccess/#redirect-http-to-https">Redirect non-https requests to https server</a></li>
  827. <li><a title="redirect HTTP to HTTPS without mod_ssl!" href="/htaccess/ssl-example-usage-in-htaccess/#rewrite-http-to-https-no-mod_ssl">Rewrite non-https to HTTPS without mod_ssl!</a></li>
  828. <li><a title="Redirect HTTP to HTTPS by port" href="/htaccess/ssl-example-usage-in-htaccess/#redirect-port-80-to-https">Redirect everything served on port 80 to HTTPS URI</a></li>
  829. </ul>
  830. <h3><a title="Conditionally setting variables in Apache .htaccess" rel="chapter" href="https://www.askapache.com/htaccess/setenvif/">SetEnvIf and SetEnvIfNoCase in .htaccess</a></h3>
  831. <ul>
  832. <li><a title="Unique mod_setenvif Variables" href="/htaccess/setenvif/#setenvif-variables">Unique mod_setenvif Variables</a></li>
  833. <li><a title="Populates HTTP_MY_ Variables with mod_setenvif variable values" href="/htaccess/setenvif/#http-headers">Populates HTTP_MY_ Variables with mod_setenvif variable values</a></li>
  834. <li><a title="Allows only if HOST Header is present in request" href="/htaccess/setenvif/#allow-host">Allows only if HOST Header is present in request</a></li>
  835. <li><a title="Add values from HTTP Headers" href="/htaccess/setenvif/#header-copy">Add values from HTTP Headers</a></li>
  836. </ul>
  837. <h3><a title="htaccess security and hacking" rel="chapter" href="https://www.askapache.com/htaccess/security-with-htaccess/">Site Security with .htaccess</a></h3>
  838. 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)
  839. <ul>
  840. <li><a title="CHMOD .htaccess, chmod .htpasswd, chmodding files" href="/htaccess/security-with-htaccess/#chmod-htaccess-info">CHMOD your files</a></li>
  841. <li><a title="Deny access for htaccess/htpasswd file" href="/htaccess/security-with-htaccess/#deny-htaccess-htpasswd-access">Prevent access to .htaccess and .htpasswd files</a></li>
  842. <li><a title="Show source code in browser, prevent executing file" href="/htaccess/security-with-htaccess/#show-source-code">Show Source Code instead of executing</a></li>
  843. <li><a title="Remove execution privileges" href="/htaccess/security-with-htaccess/#securing-directories-with-htaccess">Securing directories: Remove ability to execute scripts</a></li>
  844. <li><a title="ErrorDocument usage in htaccess files" href="/htaccess/security-with-htaccess/#errordocument-usage-in-htaccess">.htaccess ErrorDocuments</a></li>
  845. </ul>
  846. <h3>Merging Notes</h3>
  847. The order of merging is:
  848. <ol>
  849. <li><code>&lt;Directory&gt;</code> (except regular expressions) and .htaccess done simultaneously (with .htaccess, if allowed, overriding <code>&lt;Directory&gt;</code>)</li>
  850. <li><code>&lt;DirectoryMatch&gt;</code> (and <code>&lt;Directory ~&gt;</code>)</li>
  851. <li><code>&lt;Files&gt;</code> and <code>&lt;FilesMatch&gt;</code> done simultaneously</li>
  852. <li><code>&lt;Location&gt;</code> and <code>&lt;LocationMatch&gt;</code> done simultaneously</li>
  853. </ol>
  854. <h2>My Favorite .htaccess Links</h2>
  855. <p class="anote">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.</p>
  856. <strong>NCSA HTTPd Tutorials</strong>
  857.  
  858. <strong>Robert Hansen</strong>
  859. Here's a great <a href="http://www.securityfocus.com/infocus/1368">Hardening HTAccess part 1</a>, <a href="http://www.securityfocus.com/infocus/1369">part 2</a>, <a href="http://www.securityfocus.com/infocus/1370">part 3</a> article that goes into detail about some of the rarer security applications for .htaccess files.
  860.  
  861. <strong>SAMAXES</strong>
  862. Some very detailed and helpful .htaccess articles, such as the <a href="http://www.samaxes.com/2008/04/20/htaccess-gzip-and-cache-your-site-for-faster-loading-and-bandwidth-saving/">".htaccess - gzip and cache your site for faster loading and bandwidth saving."</a>
  863.  
  864. <strong>PerishablePress</strong>
  865. <a href="http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/">Stupid .htaccess tricks</a> is probably the <strong>best explanation online</strong> 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 <a title="Eight Ways to Blacklist with Apache's mod_rewrite" href="http://perishablepress.com/press/2009/02/03/eight-ways-to-blacklist-with-apaches-mod_rewrite/">fantastic article</a> detailing how to block/deny specific requests using mod_rewrite.
  866.  
  867. <strong>BlogSecurity</strong>
  868. 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.
  869.  
  870. <strong>Check-These</strong>
  871. 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: <a href="http://check-these.info/mod_rewrite-basic.html">Basic Mod_Rewrite Guide</a>, and <a href="http://check-these.info/RewriteRule.html">Advanced Mod_Rewrite Tutorial</a>
  872.  
  873. <strong>Reaper-X</strong>
  874. Alot of .htaccess tutorials and code.  See: <a href="http://www.reaper-x.com/2007/09/01/hardening-wordpress-with-mod-rewrite-and-htaccess/">Hardening Wordpress with Mod Rewrite and htaccess</a>
  875.  
  876. <strong>jdMorgan</strong>
  877. <a href="http://www.webmasterworld.com/profilev4.cgi?action=view&amp;member=jdMorgan">jdMorgan</a> is the Moderator of the <a href="http://www.webmasterworld.com/apache/">Apache Forum</a> 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.
  878.  
  879. <strong>The W3C</strong>
  880. <a href="http://www.w3.org/International/questions/qa-htaccess-charset">Setting Charset in .htaccess</a> is very informative.
  881.  
  882. <strong>Holy Shmoly!</strong>
  883. A great blogger with analysis of attacks and spam.  See: More ways to stop spammers and unwanted traffic.
  884.  
  885. <strong>Apache Week</strong>
  886. A partnership with Red Hat back in the 90's that produced some <a href="http://www.apacheweek.com/features/userauth">excellent documentation</a>.
  887.  
  888. <strong>Corz</strong>
  889. 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: <a rel="nofollow" href="http://corz.org/serv/tricks/htaccess.php">htaccess tricks and tips</a>.
  890. <h2>Htaccess Directives</h2>
  891. <p class="anote">This is an AskApache.com exclusive <em>you won't find this anywhere else</em>.</p>
  892. AcceptFilter, AcceptMutex, <a href="/htaccess-file/directive/acceptpathinfo/">AcceptPathInfo</a>, <a href="/htaccess-file/directive/accessfilename/">AccessFileName</a>, <a href="/htaccess-file/directive/action/">Action</a>, AddAlt, AddAltByEncoding, AddAltByType, <a href="/htaccess-file/directive/addcharset/">AddCharset</a>, <a href="/htaccess-file/directive/adddefaultcharset/">AddDefaultCharset</a>, <a href="/htaccess-file/directive/adddescription/">AddDescription</a>, <a href="/htaccess-file/directive/addencoding/">AddEncoding</a>, <a href="/htaccess-file/directive/addhandler/">AddHandler</a>, <a href="/htaccess-file/directive/addicon/">AddIcon</a>, <a href="/htaccess-file/directive/addiconbytype/">AddIconByType</a>, <a href="/htaccess-file/directive/addiconbyencoding/">AddIconByEncoding</a>, <a href="/htaccess-file/directive/addiconbyencoding/">AddIconByEncoding</a>, <a href="/htaccess-file/directive/addiconbytype/">AddIconByType</a>, AddInputFilter, <a href="/htaccess-file/directive/addlanguage/">AddLanguage</a>, AddModuleInfo, <a href="/htaccess-file/directive/addoutputfilterbytype/">AddOutputFilterByType</a>, <a href="/htaccess-file/directive/addoutputfilter/">AddOutputFilter</a>, <a href="/htaccess-file/directive/addoutputfilterbytype/">AddOutputFilterByType</a>, <a href="/htaccess-file/directive/addtype/">AddType</a>, <a href="/htaccess-file/directive/alias/">Alias</a>, <a href="/htaccess-file/directive/scriptalias/">ScriptAlias</a>, <a href="/htaccess-file/directive/serveralias/">ServerAlias</a>, AliasMatch, <a href="/htaccess-file/directive/allow/">Allow</a>, <a href="/htaccess-file/directive/allowoverride/">AllowOverride</a>, <a href="/htaccess-file/directive/allowencodedslashes/">AllowEncodedSlashes</a>, <a href="/htaccess-file/variable/_routing__allow_get/">_ROUTING__allow_GET</a>, <a href="/htaccess-file/variable/_routing__allow_head/">_ROUTING__allow_HEAD</a>, <a href="/htaccess-file/variable/_routing__allow_post/">_ROUTING__allow_POST</a>, <a href="/htaccess-file/directive/allow/">Allow</a>, <a href="/htaccess-file/directive/allowoverride/">AllowOverride</a>, <a href="/htaccess-file/directive/allowencodedslashes/">AllowEncodedSlashes</a>, AllowCONNECT, <a href="/htaccess-file/directive/allowencodedslashes/">AllowEncodedSlashes</a>, AllowMethods, <a href="/htaccess-file/directive/allowoverride/">AllowOverride</a>, AllowOverrideList, <a href="/htaccess-file/directive/anonymous/">Anonymous</a>, <a href="/htaccess-file/directive/anonymous_logemail/">Anonymous_LogEmail</a>, <a href="/htaccess-file/directive/anonymous_nouserid/">Anonymous_NoUserID</a>, Anonymous_Authoritative, <a href="/htaccess-file/directive/anonymous_logemail/">Anonymous_LogEmail</a>, Anonymous_MustGiveEmail, Anonymous_NoUserId, Anonymous_VerifyEmail, AssignUserID, AsyncRequestWorkerFactor, AuthAuthoritative, <a href="/htaccess-file/directive/authbasicauthoritative/">AuthBasicAuthoritative</a>, AuthBasicFake, <a href="/htaccess-file/directive/authbasicprovider/">AuthBasicProvider</a>, AuthBasicUseDigestAlgorithm, AuthDBDUserPWQuery, AuthDBDUserRealmQuery, AuthDBMAuthoritative, <a href="/htaccess-file/directive/authdbmgroupfile/">AuthDBMGroupFile</a>, <a href="/htaccess-file/directive/authdbmtype/">AuthDBMType</a>, <a href="/htaccess-file/directive/authdbmuserfile/">AuthDBMUserFile</a>, AuthDefaultAuthoritative, AuthDigestAlgorithm, <a href="/htaccess-file/directive/authdigestdomain/">AuthDigestDomain</a>, <a href="/htaccess-file/directive/authdigestfile/">AuthDigestFile</a>, AuthDigestGroupFile, AuthDigestNcCheck, AuthDigestNonceFormat, AuthDigestNonceLifetime, <a href="/htaccess-file/directive/authdigestprovider/">AuthDigestProvider</a>, AuthDigestQop, AuthDigestShmemSize, AuthFormAuthoritative, AuthFormBody, AuthFormDisableNoStore, AuthFormFakeBasicAuth, AuthFormLocation, AuthFormLoginRequiredLocation, AuthFormLoginSuccessLocation, AuthFormLogoutLocation, AuthFormMethod, AuthFormMimetype, AuthFormPassword, AuthFormProvider, AuthFormSitePassphrase, AuthFormSize, AuthFormUsername, <a href="/htaccess-file/directive/authgroupfile/">AuthGroupFile</a>, <a href="/htaccess-file/directive/authldapauthoritative/">AuthLDAPAuthoritative</a>, AuthLDAPAuthorizePrefix, AuthLDAPAuthzEnabled, AuthLDAPBindAuthoritative, AuthLDAPBindDN, AuthLDAPBindPassword, AuthLDAPCharsetConfig, AuthLDAPCompareAsUser, AuthLDAPCompareDNOnServer, AuthLDAPDereferenceAliases, AuthLDAPEnabled, AuthLDAPFrontPageHack, <a href="/htaccess-file/directive/authldapgroupattribute/">AuthLDAPGroupAttribute</a>, <a href="/htaccess-file/directive/authldapgroupattributeisdn/">AuthLDAPGroupAttributeIsDN</a>, <a href="/htaccess-file/directive/authldapgroupattributeisdn/">AuthLDAPGroupAttributeIsDN</a>, AuthLDAPInitialBindAsUser, AuthLDAPInitialBindPattern, AuthLDAPMaxSubGroupDepth, AuthLDAPRemoteUserAttribute, AuthLDAPRemoteUserIsDN, AuthLDAPSearchAsUser, AuthLDAPSubGroupAttribute, AuthLDAPSubGroupClass, AuthLDAPURL, AuthMerging, <a href="/htaccess-file/directive/authname/">AuthName</a>, AuthnCacheContext, AuthnCacheEnable, AuthnCacheProvideFor, AuthnCacheProvider, AuthnCacheSOCache, <a href="/htaccess-file/directive/authncachetimeout/">AuthnCacheTimeout</a>, AuthnzFcgiCheckAuthnProvider, AuthnzFcgiDefineProvider, <a href="/htaccess-file/directive/authtype/">AuthType</a>, <a href="/htaccess-file/directive/authuserfile/">AuthUserFile</a>, AuthzDBDLoginToReferer, AuthzDBDQuery, AuthzDBDRedirectQuery, AuthzDBMAuthoritative, AuthzDBMType, AuthzDefaultAuthoritative, <a href="/htaccess-file/directive/authzgroupfileauthoritative/">AuthzGroupFileAuthoritative</a>, <a href="/htaccess-file/directive/authzldapauthoritative/">AuthzLDAPAuthoritative</a>, AuthzOwnerAuthoritative, AuthzSendForbiddenOnFailure, AuthzUserAuthoritative, BalancerGrowth, BalancerInherit, BalancerMember, BalancerNonce, BalancerPersist, <a href="/htaccess-file/directive/browsermatch/">BrowserMatch</a>, <a href="/htaccess-file/directive/browsermatchnocase/">BrowserMatchNoCase</a>, <a href="/htaccess-file/directive/browsermatchnocase/">BrowserMatchNoCase</a>, BS2000Account, BufferedLogs, <a href="/htaccess-file/directive/deflatebuffersize/">DeflateBufferSize</a>, <a href="/htaccess-file/directive/buffersize/">BufferSize</a>, <a href="/htaccess-file/directive/cachedefaultexpire/">CacheDefaultExpire</a>, CacheDetailHeader, CacheDirLength, CacheDirLevels, <a href="/htaccess-file/directive/cachedisable/">CacheDisable</a>, <a href="/htaccess-file/directive/cacheenable/">CacheEnable</a>, 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, <a href="/htaccess-file/directive/mcachesize/">MCacheSize</a>, CacheSocache, CacheSocacheMaxSize, CacheSocacheMaxTime, CacheSocacheMinTime, CacheSocacheReadSize, CacheSocacheReadTime, CacheStaleOnError, CacheStoreExpired, CacheStoreNoStore, CacheStorePrivate, CacheTimeMargin, CaseFilter, CaseFilterIn, CGIDScriptTimeout, CGIMapExtension, CGIPassAuth, CGIVar, <a href="/htaccess-file/directive/charsetdefault/">CharsetDefault</a>, CharsetOptions, <a href="/htaccess-file/directive/charsetsourceenc/">CharsetSourceEnc</a>, <a href="/htaccess-file/directive/checkcaseonly/">CheckCaseOnly</a>, <a href="/htaccess-file/directive/checkspelling/">CheckSpelling</a>, ChildperUserID, ChrootDir, ClientRecheckTime, <a href="/htaccess-file/directive/contentdigest/">ContentDigest</a>, CookieDomain, CookieExpires, CookieLog, CookieName, CookieStyle, <a href="/htaccess-file/directive/cookietracking/">CookieTracking</a>, CoreDumpDirectory, <a href="/htaccess-file/directive/customlog/">CustomLog</a>, DAV, DAVDepthInfinity, DAVGenericLockDB, DAVLockDB, DAVMinTimeout, DBDExptime, DBDInitSQL, DBDKeep, DBDMax, DBDMin, DBDParams, DBDPersist, DBDPrepareSQL, DBDriver, <a href="/htaccess-file/directive/defaulticon/">DefaultIcon</a>, <a href="/htaccess-file/directive/defaultlanguage/">DefaultLanguage</a>, DefaultRuntimeDir, <a href="/htaccess-file/directive/defaulttype/">DefaultType</a>, <a href="/htaccess-file/directive/define/">Define</a>, <a href="/htaccess-file/directive/deflatebuffersize/">DeflateBufferSize</a>, <a href="/htaccess-file/directive/deflatecompressionlevel/">DeflateCompressionLevel</a>, <a href="/htaccess-file/directive/deflatefilternote/">DeflateFilterNote</a>, DeflateInflateLimitRequestBody, DeflateInflateRatioBurst, DeflateInflateRatioLimit, DeflateMemLevel, <a href="/htaccess-file/directive/deflatewindowsize/">DeflateWindowSize</a>, <a href="/htaccess-file/directive/deny/">Deny</a>, <a href="/htaccess-file/directive/deny/">Deny</a>, <a href="/htaccess-file/directive/directoryindex/">DirectoryIndex</a>, <a href="/htaccess-file/directive/directoryslash/">DirectorySlash</a>, DirectoryCheckHandler, <a href="/htaccess-file/directive/directoryindex/">DirectoryIndex</a>, DirectoryIndexRedirect, DirectoryMatch, <a href="/htaccess-file/directive/directoryslash/">DirectorySlash</a>, <a href="/htaccess-file/directive/virtualdocumentroot/">VirtualDocumentRoot</a>, <a href="/htaccess-file/directive/documentroot/">DocumentRoot</a>, DTracePrivileges, DumpIOInput, DumpIOLogLevel, DumpIOOutput, EnableExceptionHook, EnableMMAP, <a href="/htaccess-file/directive/enablesendfile/">EnableSendfile</a>, <a href="/htaccess-file/directive/errordocument/">ErrorDocument</a>, <a href="/htaccess-file/directive/errorlog/">ErrorLog</a>, ErrorLogFormat, <a href="/htaccess-file/directive/expiresactive/">ExpiresActive</a>, <a href="/htaccess-file/directive/expiresbytype/">ExpiresByType</a>, <a href="/htaccess-file/directive/expiresdefault/">ExpiresDefault</a>, ExtendedStatus, ExtFilterDefine, ExtFilterOptions, <a href="/htaccess-file/directive/fallbackresource/">FallbackResource</a>, <a href="/htaccess-file/directive/fancyindexing/">FancyIndexing</a>, <a href="/htaccess-file/directive/fileetag/">FileETag</a>, Files, FilesMatch, <a href="/htaccess-file/directive/filterchain/">FilterChain</a>, <a href="/htaccess-file/directive/filterdeclare/">FilterDeclare</a>, <a href="/htaccess-file/directive/filterprotocol/">FilterProtocol</a>, <a href="/htaccess-file/directive/filterprovider/">FilterProvider</a>, FilterTrace, <a href="/htaccess-file/directive/forcelanguagepriority/">ForceLanguagePriority</a>, <a href="/htaccess-file/directive/forcetype/">ForceType</a>, ForensicLog, GlobalLog, GprofDir, <a href="/htaccess-file/directive/authgroupfile/">AuthGroupFile</a>, <a href="/htaccess-file/directive/group/">Group</a>, <a href="/htaccess-file/directive/authdbmgroupfile/">AuthDBMGroupFile</a>, <a href="/htaccess-file/directive/authldapgroupattribute/">AuthLDAPGroupAttribute</a>, <a href="/htaccess-file/directive/authldapgroupattributeisdn/">AuthLDAPGroupAttributeIsDN</a>, <a href="/htaccess-file/directive/authzgroupfileauthoritative/">AuthzGroupFileAuthoritative</a>, H2AltSvc, H2AltSvcMaxAge, H2Direct, H2MaxSessionStreams, H2MaxWorkerIdleSeconds, H2MaxWorkers, H2MinWorkers, H2ModernTLSOnly, H2Push, H2PushDiarySize, H2PushPriority, H2SerializeHeaders, H2SessionExtraFiles, H2StreamMaxMemSize, H2TLSCoolDownSecs, H2TLSWarmUpSize, H2Upgrade, H2WindowSize, <a href="/htaccess-file/directive/header/">Header</a>, <a href="/htaccess-file/directive/requestheader/">RequestHeader</a>, <a href="/htaccess-file/directive/headername/">HeaderName</a>, <a href="/htaccess-file/directive/headername/">HeaderName</a>, HeartbeatAddress, HeartbeatListen, HeartbeatMaxServers, HeartbeatStorage, HostnameLookups, IdentityCheck, IdentityCheckTimeout, IfDefine, IfModule, IfVersion, ImapBase, ImapDefault, ImapMenu, <a href="/htaccess-file/directive/include/">Include</a>, IncludeOptional, <a href="/htaccess-file/directive/indexheadinsert/">IndexHeadInsert</a>, <a href="/htaccess-file/directive/indexignore/">IndexIgnore</a>, IndexIgnoreReset, <a href="/htaccess-file/directive/indexoptions/">IndexOptions</a>, <a href="/htaccess-file/directive/indexorderdefault/">IndexOrderDefault</a>, <a href="/htaccess-file/directive/indexstylesheet/">IndexStyleSheet</a>, InputSed, ISAPIAppendLogToErrors, ISAPIAppendLogToQuery, ISAPICacheFile, ISAPIFakeAsync, ISAPILogNotSupported, ISAPIReadAheadBuffer, <a href="/htaccess-file/directive/keepalive/">KeepAlive</a>, <a href="/htaccess-file/directive/keepalivetimeout/">KeepAliveTimeout</a>, <a href="/htaccess-file/directive/maxkeepaliverequests/">MaxKeepAliveRequests</a>, <a href="/htaccess-file/directive/keepalivetimeout/">KeepAliveTimeout</a>, KeptBodySize, <a href="/htaccess-file/directive/languagepriority/">LanguagePriority</a>, <a href="/htaccess-file/directive/forcelanguagepriority/">ForceLanguagePriority</a>, LDAPCacheEntries, LDAPCacheTTL, LDAPConnectionPoolTTL, LDAPConnectionTimeout, LDAPLibraryDebug, LDAPOpCacheEntries, LDAPOpCacheTTL, LDAPReferralHopLimit, LDAPReferrals, LDAPRetries, LDAPRetryDelay, LDAPSharedCacheFile, LDAPSharedCacheSize, LDAPTimeout, LDAPTrustedCA, LDAPTrustedCAType, LDAPTrustedClientCert, LDAPTrustedGlobalCert, LDAPTrustedMode, LDAPVerifyServerCert, <a href="/htaccess-file/directive/limitrequestbody/">LimitRequestBody</a>, <a href="/htaccess-file/directive/rlimitmem/">RLimitMEM</a>, <a href="/htaccess-file/directive/limitrequestfields/">LimitRequestFields</a>, <a href="/htaccess-file/directive/limitrequestfieldsize/">LimitRequestFieldSize</a>, <a href="/htaccess-file/directive/limitrequestline/">LimitRequestLine</a>, LimitExcept, LimitInternalRecursion, <a href="/htaccess-file/directive/limitrequestbody/">LimitRequestBody</a>, <a href="/htaccess-file/directive/limitrequestfields/">LimitRequestFields</a>, LimitRequestFieldsize, <a href="/htaccess-file/directive/limitrequestline/">LimitRequestLine</a>, LimitXMLRequestBody, LoadFile, <a href="/htaccess-file/directive/loadmodule/">LoadModule</a>, Location, LocationMatch, LockFile, <a href="/htaccess-file/directive/logformat/">LogFormat</a>, LogIOTrackTTFB, <a href="/htaccess-file/directive/rewriteloglevel/">RewriteLogLevel</a>, <a href="/htaccess-file/directive/loglevel/">LogLevel</a>, LogMessage, LuaAuthzProvider, Lua_____ByteCodeHack, LuaCodeCache, LuaHookAccessChecker, LuaHookAuthChecker, LuaHookCheckUserID, LuaHookFixups, LuaHookInsertFilter, LuaHookLog, LuaHookMapToStorage, LuaHookTranslateName, LuaHookTypeChecker, LuaInherit, LuaInputFilter, LuaMapHandler, LuaOutputFilter, LuaPackageCPath, <a href="/htaccess-file/directive/luapackagepath/">LuaPackagePath</a>, LuaQuickHandler, LuaRoot, LuaScope, MaxClientConnections, MaxClients, MaxConnectionsPerChild, <a href="/htaccess-file/directive/maxkeepaliverequests/">MaxKeepAliveRequests</a>, MaxMemFree, MaxRangeOverlaps, MaxRangeReversals, MaxRanges, MaxRequestsPerChild, MaxRequestsPerThread, MaxRequestWorkers, MaxSpareServers, MaxSpareThreads, MaxThreads, MaxThreadsPerChild, <a href="/htaccess-file/directive/mcachemaxobjectcount/">MCacheMaxObjectCount</a>, <a href="/htaccess-file/directive/mcachemaxobjectsize/">MCacheMaxObjectSize</a>, MCacheMaxStreamingBuffer, <a href="/htaccess-file/directive/mcacheminobjectsize/">MCacheMinObjectSize</a>, MCacheRemovalAlgorithm, <a href="/htaccess-file/directive/mcachesize/">MCacheSize</a>, MemcacheConnTTL, MergeTrailers, MetaDir, MetaFiles, MetaSuffix, MimeMagicFile, MinSpareServers, MinSpareThreads, mmapfile, ModemStandard, ModMimeUsePathInfo, <a href="/htaccess-file/directive/multiviewsmatch/">MultiviewsMatch</a>, Mutex, NameVirtualHost, NoProxy, NumServers, NWSSLTrustedCerts, NWSSLUpgradeable, <a href="/htaccess-file/directive/options/">Options</a>, <a href="/htaccess-file/directive/rewriteoptions/">RewriteOptions</a>, <a href="/htaccess-file/directive/indexoptions/">IndexOptions</a>, <a href="/htaccess-file/directive/order/">Order</a>, <a href="/htaccess-file/directive/indexorderdefault/">IndexOrderDefault</a>, <a href="/htaccess-file/directive/order/">Order</a>, <a href="/htaccess-file/directive/indexorderdefault/">IndexOrderDefault</a>, OutputSed, <a href="/htaccess-file/directive/passenv/">PassEnv</a>, <a href="/htaccess-file/directive/php_admin_flag/">php_admin_flag</a>, <a href="/htaccess-file/directive/php_admin_value/">php_admin_value</a>, <a href="/htaccess-file/directive/php_flag/">php_flag</a>, <a href="/htaccess-file/directive/php_value/">php_value</a>, PidFile, <a href="/htaccess-file/directive/port/">Port</a>, PrivilegesMode, <a href="/htaccess-file/directive/filterprotocol/">FilterProtocol</a>, <a href="/htaccess-file/directive/protocol/">Protocol</a>, ProtocolEcho, Protocols, ProtocolsHonorOrder, <a href="/htaccess-file/directive/proxypass/">ProxyPass</a>, <a href="/htaccess-file/directive/proxypassmatch/">ProxyPassMatch</a>, <a href="/htaccess-file/directive/proxypassreverse/">ProxyPassReverse</a>, <a href="/htaccess-file/directive/proxyrequests/">ProxyRequests</a>, 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, <a href="/htaccess-file/directive/proxypass/">ProxyPass</a>, <a href="/htaccess-file/directive/proxypassmatch/">ProxyPassMatch</a>, <a href="/htaccess-file/directive/proxypassreverse/">ProxyPassReverse</a>, ProxyPassInherit, ProxyPassInterpolateEnv, <a href="/htaccess-file/directive/proxypassmatch/">ProxyPassMatch</a>, <a href="/htaccess-file/directive/proxypassreverse/">ProxyPassReverse</a>, ProxyPassReverseCookieDomain, ProxyPassReverseCookiePath, ProxyPreserveHost, ProxyReceiveBufferSize, ProxyRemote, ProxyRemoteMatch, <a href="/htaccess-file/directive/proxyrequests/">ProxyRequests</a>, ProxySCGIInternalRedirect, ProxySCGISendfile, ProxySet, ProxySourceAddress, ProxyStatus, ProxyTimeout, ProxyVia, QualifyRedirectURL, <a href="/htaccess-file/directive/readmename/">ReadmeName</a>, <a href="/htaccess-file/directive/redirect/">Redirect</a>, <a href="/htaccess-file/directive/redirectmatch/">RedirectMatch</a>, <a href="/htaccess-file/directive/redirecttemp/">RedirectTemp</a>, <a href="/htaccess-file/directive/redirectpermanent/">RedirectPermanent</a>, <a href="/htaccess-file/directive/redirectmatch/">RedirectMatch</a>, <a href="/htaccess-file/directive/redirectpermanent/">RedirectPermanent</a>, <a href="/htaccess-file/directive/redirecttemp/">RedirectTemp</a>, ReflectorHeader, RemoteIPHeader, RemoteIPInternalProxy, RemoteIPInternalProxyList, RemoteIPProxiesHeader, RemoteIPTrustedProxy, RemoteIPTrustedProxyList, <a href="/htaccess-file/directive/removecharset/">RemoveCharset</a>, <a href="/htaccess-file/directive/removeencoding/">RemoveEncoding</a>, <a href="/htaccess-file/directive/removehandler/">RemoveHandler</a>, RemoveInputFilter, RemoveLanguage, <a href="/htaccess-file/directive/removeoutputfilter/">RemoveOutputFilter</a>, <a href="/htaccess-file/directive/removetype/">RemoveType</a>, <a href="/htaccess-file/directive/requestheader/">RequestHeader</a>, RequestReadTimeout, RequestTimeout, <a href="/htaccess-file/directive/require/">Require</a>, <a href="/htaccess-file/directive/rewritebase/">RewriteBase</a>, <a href="/htaccess-file/directive/rewritecond/">RewriteCond</a>, <a href="/htaccess-file/directive/rewriteengine/">RewriteEngine</a>, RewriteLock, <a href="/htaccess-file/directive/rewritelog/">RewriteLog</a>, <a href="/htaccess-file/directive/rewriteloglevel/">RewriteLogLevel</a>, <a href="/htaccess-file/directive/rewriteloglevel/">RewriteLogLevel</a>, <a href="/htaccess-file/directive/rewritemap/">RewriteMap</a>, <a href="/htaccess-file/directive/rewriteoptions/">RewriteOptions</a>, <a href="/htaccess-file/directive/rewriterule/">RewriteRule</a>, RLimitCPU, <a href="/htaccess-file/directive/rlimitmem/">RLimitMEM</a>, RLimitNPROC, <a href="/htaccess-file/directive/satisfy/">Satisfy</a>, ScoreboardFile, ScoreBoardFile, <a href="/htaccess-file/directive/script/">Script</a>, <a href="/htaccess-file/directive/scriptalias/">ScriptAlias</a>, <a href="/htaccess-file/directive/scriptalias/">ScriptAlias</a>, ScriptAliasMatch, ScriptInterpreterSource, ScriptLog, ScriptLogBuffer, ScriptLogLength, Scriptsock, ScriptSock, SecureListen, SeeRequestTail, SerfCluster, SerfPass, <a href="/htaccess-file/directive/serveradmin/">ServerAdmin</a>, <a href="/htaccess-file/directive/serveralias/">ServerAlias</a>, ServerLimit, <a href="/htaccess-file/directive/servername/">ServerName</a>, ServerPath, ServerRoot, <a href="/htaccess-file/directive/serversignature/">ServerSignature</a>, <a href="/htaccess-file/directive/servertokens/">ServerTokens</a>, <a href="/htaccess-file/directive/session/">Session</a>, SessionCookieName, SessionCookieName2, SessionCookieRemove, SessionCryptoCipher, SessionCryptoDriver, SessionCryptoPassphrase, SessionCryptoPassphraseFile, SessionDBDCookieName, SessionDBDCookieName2, SessionDBDCookieRemove, SessionDBDDeleteLabel, SessionDBDInsertLabel, SessionDBDPerUser, SessionDBDSelectLabel, SessionDBDUpdateLabel, SessionEnv, SessionExclude, SessionHeader, SessionInclude, SessionMaxAge, <a href="/htaccess-file/directive/setenvifnocase/">SetEnvIfNoCase</a>, <a href="/htaccess-file/directive/setenv/">SetEnv</a>, <a href="/htaccess-file/directive/setenvif/">SetEnvIf</a>, <a href="/htaccess-file/directive/setenvifnocase/">SetEnvIfNoCase</a>, <a href="/htaccess-file/directive/setenvif/">SetEnvIf</a>, SetEnvIfExpr, <a href="/htaccess-file/directive/setenvifnocase/">SetEnvIfNoCase</a>, <a href="/htaccess-file/directive/sethandler/">SetHandler</a>, <a href="/htaccess-file/directive/setinputfilter/">SetInputFilter</a>, <a href="/htaccess-file/directive/setoutputfilter/">SetOutputFilter</a>, SimpleProcCount, SimpleThreadCount, SSIAccessEnable, SSIEndTag, SSIErrorMsg, SSIEtag, SSILastModified, SSILegacyExprParser, SSIStartTag, SSITimeFormat, SSIUndefinedEcho, SSLLog, SSLLogLevel, StartServers, StartThreads, <a href="/htaccess-file/directive/substitute/">Substitute</a>, SubstituteInheritBefore, SubstituteMaxLineLength, Suexec, SuexecUserGroup, ThreadLimit, ThreadsPerChild, ThreadStackSize, <a href="/htaccess-file/directive/keepalivetimeout/">KeepAliveTimeout</a>, <a href="/htaccess-file/directive/authncachetimeout/">AuthnCacheTimeout</a>, TraceEnable, TransferLog, TrustedProxy, TypesConfig, UnDefine, <a href="/htaccess-file/directive/unsetenv/">UnsetEnv</a>, UseCanonicalName, UseCanonicalPhysicalPort, <a href="/htaccess-file/directive/user/">User</a>, <a href="/htaccess-file/directive/authuserfile/">AuthUserFile</a>, <a href="/htaccess-file/directive/userdir/">UserDir</a>, <a href="/htaccess-file/directive/authdbmuserfile/">AuthDBMUserFile</a>, <a href="/htaccess-file/directive/anonymous_nouserid/">Anonymous_NoUserID</a>, <a href="/htaccess-file/directive/userdir/">UserDir</a>, VHostCGIMode, VHostCGIPrivs, VHostGroup, VHostPrivs, VHostSecure, VHostUser, <a href="/htaccess-file/directive/virtualdocumentroot/">VirtualDocumentRoot</a>, VirtualDocumentRootIP, VirtualHost, VirtualScriptAlias, VirtualScriptAliasIP, Win32DisableAcceptEx, <a href="/htaccess-file/directive/xbithack/">XBitHack</a>, xml2EncAlias, xml2EncDefault, xml2StartParse
  893. <h2>Htaccess Variables</h2>
  894. alias-forced-type, <a href="/htaccess-file/variable/api_version/">API_VERSION</a>, ap-mime-exceptions-list, AP_PARENT_PID, AUTHN_PROVIDER_GROUP, <a href="/htaccess-file/variable/auth_type/">AUTH_TYPE</a>, BALANCER, BALANCER_NAME, BALANCER_ROUTE_CHANGED, BALANCER_SESSION_ROUTE, BALANCER_SESSION_STICKY, BALANCER_WORKER_NAME, BALANCER_WORKER_ROUTE, <a href="/htaccess-file/variable/cache/">CACHE</a>, CACHE_CONDITIONAL, CACHE_INVALIDATE, CACHE_OUT, CACHE_OUT_SUBREQ, CACHE_REMOVE_URL, CACHE_SAVE, CACHE_SAVE_SUBREQ, <a href="/htaccess-file/variable/cert/">CERT</a>, CERT_BASE64, CERT_DER, CERT_KEY3_DB, CERT_NICKNAME, CERT_PFX, CGI_APACHE_ROLE, CGI_ROLE, CLIENT_CERT_RFC4523_CEA, CLIENT_VERIFY, COMPRESS_METHOD, <a href="/htaccess-file/variable/connection/">CONNECTION</a>, CONN_LOG_ID, CONN_REMOTE_ADDR, <a href="/htaccess-file/variable/content_length/">CONTENT_LENGTH</a>, CONTENT_SET, <a href="/htaccess-file/variable/content_type/">CONTENT_TYPE</a>, <a href="/htaccess-file/variable/context_document_root/">CONTEXT_DOCUMENT_ROOT</a>, <a href="/htaccess-file/variable/context_prefix/">CONTEXT_PREFIX</a>, DATE_GMT, DATE_LOCAL, <a href="/htaccess-file/variable/deflate/">DEFLATE</a>, DOCUMENT_ARGS, DOCUMENT_NAME, DOCUMENT_PATH_INFO, <a href="/htaccess-file/variable/document_root/">DOCUMENT_ROOT</a>, <a href="/htaccess-file/variable/document_uri/">DOCUMENT_URI</a>, <a href="/htaccess-file/variable/downgrade-1-0/">downgrade-1.0</a>, <a href="/htaccess-file/variable/env/">ENV</a>, ENVVAR_SCRIPT_URI, ENVVAR_SCRIPT_URL, ERRFN_USERDATA_KEY, error-notes, ERROR_NOTES, FCGI_APACHE_ROLE, FCGI_ROLE, filter-errordocs, force-gzip, <a href="/htaccess-file/variable/force-no-vary/">force-no-vary</a>, force-proxy-request-1.0, <a href="/htaccess-file/variable/force-response-1-0/">force-response-1.0</a>, forensic-id, <a href="/htaccess-file/variable/gateway_interface/">GATEWAY_INTERFACE</a>, <a href="/htaccess-file/variable/get/">GET</a>, <a href="/htaccess-file/variable/handler/">HANDLER</a>, <a href="/htaccess-file/variable/http_accept/">HTTP_ACCEPT</a>, HTTP_ACCEPT_CHARSET, HTTP_ACCEPT_ENCODING, HTTP_ACCEPT_LANGUAGE, <a href="/htaccess-file/variable/http_cache_control/">HTTP_CACHE_CONTROL</a>, <a href="/htaccess-file/variable/http_connection/">HTTP_CONNECTION</a>, <a href="/htaccess-file/variable/http_cookie/">HTTP_COOKIE</a>, <a href="/htaccess-file/variable/http_forwarded/">HTTP_FORWARDED</a>, <a href="/htaccess-file/variable/http_host/">HTTP_HOST</a>, <a href="/htaccess-file/variable/http_keep_alive/">HTTP_KEEP_ALIVE</a>, <a href="/htaccess-file/variable/http_pc_remote_addr/">HTTP_PC_REMOTE_ADDR</a>, <a href="/htaccess-file/variable/http_proxy_connection/">HTTP_PROXY_CONNECTION</a>, <a href="/htaccess-file/variable/http_referer/">HTTP_REFERER</a>, <a href="/htaccess-file/variable/http_request/">HTTP_REQUEST</a>, <a href="/htaccess-file/variable/https/">HTTPS</a>, HTTPS_HOST, HTTP_TE, HTTP_TRAILER, HTTP_TRANSFER_ENCODING, HTTP_UPGRADE, <a href="/htaccess-file/variable/http_user_agent/">HTTP_USER_AGENT</a>, <a href="/htaccess-file/variable/http_user_agent/">HTTP_USER_AGENT</a>, <a href="/htaccess-file/variable/http_wp_version_folder_name/">HTTP_WP_VERSION_FOLDER_NAME</a>, <a href="/htaccess-file/variable/if-modified-since/">If-Modified-Since</a>, <a href="/htaccess-file/variable/if-none-match/">If-None-Match</a>, <a href="/htaccess-file/variable/includes/">INCLUDES</a>, INFLATE, <a href="/htaccess-file/variable/installpath/">installpath</a>, IPV6, <a href="/htaccess-file/variable/is_subreq/">IS_SUBREQ</a>, KEY_BASE64, KEY_DER, KEY_PFX, LAST_MODIFIED, LDAP_BINDASUSER, mod_rewrite_rewritten, mod_userdir_user, <a href="/htaccess-file/variable/no-cache/">no-cache</a>, no-etag, <a href="/htaccess-file/variable/no-gzip/">no-gzip</a>, <a href="/htaccess-file/variable/nokeepalive/">nokeepalive</a>, nwconv-ssl, <a href="/htaccess-file/variable/origin/">ORIGIN</a>, <a href="/htaccess-file/variable/origin_is/">origin_is</a>, ORIGIN_SUB_DOMAIN, <a href="/htaccess-file/variable/orig_path_info/">ORIG_PATH_INFO</a>, <a href="/htaccess-file/variable/orig_path_translated/">ORIG_PATH_TRANSLATED</a>, <a href="/htaccess-file/variable/orig_script_filename/">ORIG_SCRIPT_FILENAME</a>, <a href="/htaccess-file/variable/orig_script_name/">ORIG_SCRIPT_NAME</a>, <a href="/htaccess-file/variable/path_info/">PATH_INFO</a>, PATH_TRANSLATED, <a href="/htaccess-file/variable/php_self/">PHP_SELF</a>, <a href="/htaccess-file/variable/platform/">PLATFORM</a>, <a href="/htaccess-file/variable/post/">POST</a>, <a href="/htaccess-file/variable/pragma/">Pragma</a>, <a href="/htaccess-file/variable/profile/">Profile</a>, <a href="/htaccess-file/variable/proto/">PROTO</a>, <a href="/htaccess-file/directive/protocol/">Protocol</a>, <a href="/htaccess-file/variable/protocol/">PROTOCOL</a>, <a href="/htaccess-file/variable/protossl/">protossl</a>, <a href="/htaccess-file/variable/proxy_connection/">PROXY_CONNECTION</a>, 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, <a href="/htaccess-file/variable/p_suffix/">P_SUFFIX</a>, push-policy, <a href="/htaccess-file/variable/put/">PUT</a>, <a href="/htaccess-file/variable/query_string/">QUERY_STRING</a>, <a href="/htaccess-file/variable/query_string/">QUERY_STRING</a>, QUERY_STRING_UNESCAPED, rate-limit, <a href="/htaccess-file/variable/redirect_breakpoint/">REDIRECT_BREAKPOINT</a>, <a href="/htaccess-file/variable/redirect-carefull/">redirect-carefull</a>, redirect-carefully, REDIRECT_ENVVAR_SCRIPT_URL, <a href="/htaccess-file/variable/redirect_query_string/">REDIRECT_QUERY_STRING</a>, <a href="/htaccess-file/variable/redirect_redirect_status/">REDIRECT_REDIRECT_STATUS</a>, <a href="/htaccess-file/variable/redirect_remote_user/">REDIRECT_REMOTE_USER</a>, <a href="/htaccess-file/variable/redirect_status/">REDIRECT_STATUS</a>, REDIRECT_UNIQUE_ID, <a href="/htaccess-file/variable/redirect_url/">REDIRECT_URL</a>, <a href="/htaccess-file/variable/redirect_x_rewrite/">REDIRECT_X_REWRITE</a>, <a href="/htaccess-file/variable/remote_addr/">REMOTE_ADDR</a>, <a href="/htaccess-file/variable/remote_host/">REMOTE_HOST</a>, <a href="/htaccess-file/variable/remote_ident/">REMOTE_IDENT</a>, remoteip-proxy-ip-list, REMOTE_PASSWD, <a href="/htaccess-file/variable/remote_port/">REMOTE_PORT</a>, <a href="/htaccess-file/variable/remote_user/">REMOTE_USER</a>, REQUEST_ACCESS, <a href="/htaccess-file/variable/request_filename/">REQUEST_FILENAME</a>, <a href="/htaccess-file/variable/request_filename/">REQUEST_FILENAME</a>, <a href="/htaccess-file/variable/request_filename/">REQUEST_FILENAME</a>, <a href="/htaccess-file/variable/request_filname/">REQUEST_FILNAME</a>, REQUEST_LOG_ID, <a href="/htaccess-file/variable/request_method/">REQUEST_METHOD</a>, <a href="/htaccess-file/variable/request_scheme/">REQUEST_SCHEME</a>, <a href="/htaccess-file/variable/request_status/">REQUEST_STATUS</a>, <a href="/htaccess-file/variable/request_time/">REQUEST_TIME</a>, <a href="/htaccess-file/variable/request_uri/">REQUEST_URI</a>, <a href="/htaccess-file/variable/request_uri/">REQUEST_URI</a>, <a href="/htaccess-file/variable/request_uri/">REQUEST_URI</a>, <a href="/htaccess-file/variable/request_url/">REQUEST_URL</a>, <a href="/htaccess-file/directive/rewritebase/">RewriteBase</a>, <a href="/htaccess-file/variable/rewritebase/">REWRITEBASE</a>, rewrite-proxy, <a href="/htaccess-file/variable/_routing__allow_get/">_ROUTING__allow_GET</a>, <a href="/htaccess-file/variable/_routing__allow_head/">_ROUTING__allow_HEAD</a>, <a href="/htaccess-file/variable/_routing__allow_post/">_ROUTING__allow_POST</a>, <a href="/htaccess-file/variable/script_filename/">SCRIPT_FILENAME</a>, <a href="/htaccess-file/variable/script_group/">SCRIPT_GROUP</a>, <a href="/htaccess-file/variable/script_name/">SCRIPT_NAME</a>, <a href="/htaccess-file/variable/script_uri/">SCRIPT_URI</a>, <a href="/htaccess-file/variable/script_url/">SCRIPT_URL</a>, <a href="/htaccess-file/variable/script_user/">SCRIPT_USER</a>, <a href="/htaccess-file/variable/search/">SEARCH</a>, SECURE_RENEG, <a href="/htaccess-file/variable/server_addr/">SERVER_ADDR</a>, <a href="/htaccess-file/variable/server_admin/">SERVER_ADMIN</a>, <a href="/htaccess-file/variable/server_name/">SERVER_NAME</a>, <a href="/htaccess-file/variable/server_port/">SERVER_PORT</a>, SERVER_PORT_SECURE, <a href="/htaccess-file/variable/server_protocol/">SERVER_PROTOCOL</a>, <a href="/htaccess-file/variable/server_signature/">SERVER_SIGNATURE</a>, <a href="/htaccess-file/variable/server_software/">SERVER_SOFTWARE</a>, SESSION_ID, session-route, session-sticky, short-lingering-close, <a href="/htaccess-file/variable/site_dir/">site_dir</a>, 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, <a href="/htaccess-file/variable/ssl_client_cert/">SSL_CLIENT_CERT</a>, 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, <a href="/htaccess-file/variable/ssl_client_verify/">SSL_CLIENT_VERIFY</a>, 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, <a href="/htaccess-file/variable/ssl_server_cert/">SSL_SERVER_CERT</a>, 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, <a href="/htaccess-file/variable/static/">static</a>, <a href="/htaccess-file/variable/sub_path/">SUB_PATH</a>, <a href="/htaccess-file/variable/the_request/">THE_REQUEST</a>, <a href="/htaccess-file/variable/time/">TIME</a>, TIME_DAY, TIME_HOUR, TIME_MIN, TIME_MON, TIME_SEC, TIME_WDAY, TIME_YEAR, TLS_SNI, <a href="/htaccess-file/variable/tz/">TZ</a>, uds_path, <a href="/htaccess-file/variable/unique_id/">UNIQUE_ID</a>, UNMAPPED_REMOTE_USER, <a href="/htaccess-file/variable/useragent_via/">USERAGENT_VIA</a>, USER_NAME, <a href="/htaccess-file/variable/usingssl/">usingSSL</a>, variant-list, VARIANTS, verbose-error-to, <a href="/htaccess-file/variable/w3tc_domain/">W3TC_DOMAIN</a>, <a href="/htaccess-file/variable/w3tc_enc/">W3TC_ENC</a>, <a href="/htaccess-file/variable/w3tc_preview/">W3TC_PREVIEW</a>, <a href="/htaccess-file/variable/w3tc_ref/">W3TC_REF</a>, <a href="/htaccess-file/variable/w3tc_ssl/">W3TC_SSL</a>, <a href="/htaccess-file/variable/w3tc_ua/">W3TC_UA</a>, <a href="/htaccess-file/variable/wrdfnc_enc/">WRDFNC_ENC</a>, <a href="/htaccess-file/variable/wrdfnc_https/">WRDFNC_HTTPS</a>, <a href="/htaccess-file/variable/xauthorization/">XAUTHORIZATION</a>, <a href="/htaccess-file/variable/x_forwarded_for/">X_FORWARDED_FOR</a>, <a href="/htaccess-file/variable/x-forwarded-proto/">X-Forwarded-Proto</a>, <a href="/htaccess-file/variable/x-forwarded-server/">X-Forwarded-Server</a>, <a href="/htaccess-file/variable/x-forwarded-ssl/">X-Forwarded-SSL</a>, <a href="/htaccess-file/variable/xproxy_connection/">XPROXY_CONNECTION</a>, <a href="/htaccess-file/variable/x-requested-with/">X-Requested-With</a>, <a href="/htaccess-file/variable/x-wap-profile/">X-Wap-Profile</a>, <a href="/htaccess-file/variable/zip_ext/">ZIP_EXT</a>
  895. <h2>Htaccess Modules</h2>
  896. Here are most of the modules that come with Apache.  Each one can have new commands that can be used in .htaccess file scopes.
  897.  
  898. <a href="/pub/servers/mod_actions.c.html">mod_actions</a>, <a href="/pub/servers/mod_alias.c.html">mod_alias</a>, <a href="/pub/servers/mod_asis.c.html">mod_asis</a>, <a href="/pub/servers/mod_auth_basic.c.html">mod_auth_basic</a>, <a href="/pub/servers/mod_auth_digest.c.html">mod_auth_digest</a>, <a href="/pub/servers/mod_authn_anon.c.html">mod_authn_anon</a>, <a href="/pub/servers/mod_authn_dbd.c.html">mod_authn_dbd</a>, <a href="/pub/servers/mod_authn_dbm.c.html">mod_authn_dbm</a>, <a href="/pub/servers/mod_authn_default.c.html">mod_authn_default</a>, <a href="/pub/servers/mod_authn_file.c.html">mod_authn_file</a>, <a href="/pub/servers/mod_authz_dbm.c.html">mod_authz_dbm</a>, <a href="/pub/servers/mod_authz_default.c.html">mod_authz_default</a>, <a href="/pub/servers/mod_authz_groupfile.c.html">mod_authz_groupfile</a>, <a href="/pub/servers/mod_authz_host.c.html">mod_authz_host</a>, <a href="/pub/servers/mod_authz_owner.c.html">mod_authz_owner</a>, <a href="/pub/servers/mod_authz_user.c.html">mod_authz_user</a>, <a href="/pub/servers/mod_autoindex.c.html">mod_autoindex</a>, <a href="/pub/servers/mod_cache.c.html">mod_cache</a>, <a href="/pub/servers/mod_cern_meta.c.html">mod_cern_meta</a>, <a href="/pub/servers/mod_cgi.c.html">mod_cgi</a>, <a href="/pub/servers/mod_dav.c.html">mod_dav</a>, <a href="/pub/servers/mod_dav_fs.c.html">mod_dav_fs</a>, <a href="/pub/servers/mod_dbd.c.html">mod_dbd</a>, <a href="/pub/servers/mod_deflate.c.html">mod_deflate</a>, <a href="/pub/servers/mod_dir.c.html">mod_dir</a>, <a href="/pub/servers/mod_disk_cache.c.html">mod_disk_cache</a>, <a href="/pub/servers/mod_dumpio.c.html">mod_dumpio</a>, <a href="/pub/servers/mod_env.c.html">mod_env</a>, <a href="/pub/servers/mod_expires.c.html">mod_expires</a>, <a href="/pub/servers/mod_ext_filter.c.html">mod_ext_filter</a>, <a href="/pub/servers/mod_file_cache.c.html">mod_file_cache</a>, <a href="/pub/servers/mod_filter.c.html">mod_filter</a>, <a href="/pub/servers/mod_headers.c.html">mod_headers</a>, <a href="/pub/servers/mod_ident.c.html">mod_ident</a>, <a href="/pub/servers/mod_imagemap.c.html">mod_imagemap</a>, <a href="/pub/servers/mod_include.c.html">mod_include</a>, <a href="/pub/servers/mod_info.c.html">mod_info</a>, <a href="/pub/servers/mod_log_config.c.html">mod_log_config</a>, <a href="/pub/servers/mod_log_forensic.c.html">mod_log_forensic</a>, <a href="/pub/servers/mod_logio.c.html">mod_logio</a>, <a href="/pub/servers/mod_mem_cache.c.html">mod_mem_cache</a>, <a href="/pub/servers/mod_mime.c.html">mod_mime</a>, <a href="/pub/servers/mod_mime_magic.c.html">mod_mime_magic</a>, <a href="/pub/servers/mod_negotiation.c.html">mod_negotiation</a>, <a href="/pub/servers/mod_proxy.c.html">mod_proxy</a>, <a href="/pub/servers/mod_proxy_ajp.c.html">mod_proxy_ajp</a>, <a href="/pub/servers/mod_proxy_balancer.c.html">mod_proxy_balancer</a>, <a href="/pub/servers/mod_proxy_connect.c.html">mod_proxy_connect</a>, <a href="/pub/servers/mod_proxy_ftp.c.html">mod_proxy_ftp</a>, <a href="/pub/servers/mod_proxy_http.c.html">mod_proxy_http</a>, <a href="/pub/servers/mod_rewrite.c.html">mod_rewrite</a>, <a href="/pub/servers/mod_setenvif.c.html">mod_setenvif</a>, <a href="/pub/servers/mod_speling.c.html">mod_speling</a>, <a href="/pub/servers/mod_ssl.c.html">mod_ssl</a>, <a href="/pub/servers/mod_status.c.html">mod_status</a>, <a href="/pub/servers/mod_substitute.c.html">mod_substitute</a>, <a href="/pub/servers/mod_unique_id.c.html">mod_unique_id</a>, <a href="/pub/servers/mod_userdir.c.html">mod_userdir</a>, <a href="/pub/servers/mod_usertrack.c.html">mod_usertrack</a>, <a href="/pub/servers/mod_version.c.html">mod_version</a>, <a href="/pub/servers/mod_vhost_alias.c.html">mod_vhost_alias</a>
  899. <h2>Htaccess Software</h2>
  900. Apache HTTP Server comes with the following <a href="http://httpd.apache.org/docs/trunk/programs/">programs</a>.
  901. <dl>
  902. <dt><code>httpd</code></dt>
  903. <dd>Apache hypertext transfer protocol server</dd>
  904. <dt><code>apachectl</code></dt>
  905. <dd>Apache HTTP server control interface</dd>
  906. <dt><code>ab</code></dt>
  907. <dd>Apache HTTP server benchmarking tool</dd>
  908. <dt><code>apxs</code></dt>
  909. <dd>APache eXtenSion tool</dd>
  910. <dt><code>dbmmanage</code></dt>
  911. <dd>Create and update user authentication files in DBM format for basic authentication</dd>
  912. <dt><code>fcgistarter</code></dt>
  913. <dd>Start a FastCGI program</dd>
  914. <dt><code>htcacheclean</code></dt>
  915. <dd>Clean up the disk cache</dd>
  916. <dt><code>htdigest</code></dt>
  917. <dd>Create and update user authentication files for digest authentication</dd>
  918. <dt><code>htdbm</code></dt>
  919. <dd>Manipulate DBM password databases.</dd>
  920. <dt><code>htpasswd</code></dt>
  921. <dd>Create and update user authentication files for basic authentication</dd>
  922. <dt><code>httxt2dbm</code></dt>
  923. <dd>Create dbm files for use with RewriteMap</dd>
  924. <dt><code>logresolve</code></dt>
  925. <dd>Resolve hostnames for IP-addresses in Apache logfiles</dd>
  926. <dt>log_server_status</dt>
  927. <dd>Periodically log the server's status</dd>
  928. <dt><code>rotatelogs</code></dt>
  929. <dd>Rotate Apache logs without having to kill the server</dd>
  930. <dt>split-logfile</dt>
  931. <dd>Split a multi-vhost logfile into per-host logfiles</dd>
  932. <dt><code>suexec</code></dt>
  933. <dd>Switch User For Exec</dd>
  934. </dl>
  935. <h2>Technical Look at .htaccess</h2>
  936. <a href="http://httpd.apache.org/docs/1.3/misc/API.html">Source: Apache API notes</a>
  937. <h3>Per-directory configuration structures</h3>
  938. Let's look out how all of this plays out in mod_mime.c, which defines the file typing handler which emulates the NCSA server's behavior of determining file types from suffixes. What we'll be looking at, here, is the code which implements the AddType and AddEncoding commands. These commands can appear in .htaccess files, so they must be handled in the module's private per-directory data, which in fact, consists of two separate tables for MIME types and encoding information, and is declared as follows:
  939. <pre>table *forced_types;      /* Additional AddTyped stuff */
  940. table *encoding_types;    /* Added with AddEncoding... */
  941. mime_dir_config;</pre>
  942. When the server is reading a configuration file, or &lt;Directory&gt; section, which includes one of the MIME module's commands, it needs to create a mime_dir_config structure, so those commands have something to act on. It does this by invoking the function it finds in the module's `create per-dir config slot', with two arguments: the name of the directory to which this configuration information applies (or NULL for srm.conf), and a pointer to a resource pool in which the allocation should happen.
  943.  
  944. (If we are reading a .htaccess file, that resource pool is the per-request resource pool for the request; otherwise it is a resource pool which is used for configuration data, and cleared on restarts. Either way, it is important for the structure being created to vanish when the pool is cleared, by registering a cleanup on the pool if necessary).
  945.  
  946. For the MIME module, the per-dir config creation function just ap_pallocs the structure above, and a creates a couple of tables to fill it. That looks like this:
  947. <pre>void *create_mime_dir_config (pool *p, char *dummy)
  948. mime_dir_config *new = (mime_dir_config *) ap_palloc (p, sizeof(mime_dir_config));
  949.  
  950. new-&gt;forced_types = ap_make_table (p, 4);
  951. new-&gt;encoding_types = ap_make_table (p, 4);</pre>
  952. Now, suppose we've just read in a .htaccess file. We already have the per-directory configuration structure for the next directory up in the hierarchy. If the .htaccess file we just read in didn't have any AddType or AddEncoding commands, its per-directory config structure for the MIME module is still valid, and we can just use it. Otherwise, we need to merge the two structures somehow.
  953.  
  954. To do that, the server invokes the module's per-directory config merge function, if one is present. That function takes three arguments: the two structures being merged, and a resource pool in which to allocate the result. For the MIME module, all that needs to be done is overlay the tables from the new per-directory config structure with those from the parent:
  955. <pre>void *merge_mime_dir_configs (pool *p, void *parent_dirv, void *subdirv)
  956. mime_dir_config *parent_dir = (mime_dir_config *)parent_dirv;
  957. mime_dir_config *subdir = (mime_dir_config *)subdirv;
  958. mime_dir_config *new =  (mime_dir_config *)ap_palloc (p, sizeof(mime_dir_config));
  959. new-&gt;forced_types = ap_overlay_tables (p, subdir-&gt;forced_types, parent_dir-&gt;forced_types);
  960. new-&gt;encoding_types = ap_overlay_tables (p, subdir-&gt;encoding_types, parent_dir-&gt;encoding_types);</pre>
  961. As a note --- if there is no per-directory merge function present, the server will just use the subdirectory's configuration info, and ignore the parent's. For some modules, that works just fine (e.g., for the includes module, whose per-directory configuration information consists solely of the state of the XBITHACK), and for those modules, you can just not declare one, and leave the corresponding structure slot in the module itself NULL.
  962. <h3>Command handling</h3>
  963. 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):
  964. <pre>char *add_type(cmd_parms *cmd, mime_dir_config *m, char *ct, char *ext)
  965. if (*ext == &#039;.&#039;) ++ext;
  966. ap_table_set (m-&gt;forced_types, ext, ct);</pre>
  967. 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.
  968.  
  969. 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).
  970.  
  971. The MIME module's command table has entries for these commands, which look like this:
  972. <pre>command_rec mime_cmds[] =
  973. { "AddType", add_type, NULL, OR_FILEINFO, TAKE2, "a mime type followed by a file extension" },
  974. { "AddEncoding", add_encoding, NULL, OR_FILEINFO, TAKE2, "an encoding (e.g., gzip), followed by a file extension" },</pre>
  975. 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
  976. <h5>mod_autoindex</h5>
  977. <pre class="prettyprint lang-config">AddIcon, add_icon, BY_PATH, DIR_CMD_PERMS, an icon URL followed by one or more filenames
  978. AddIconByType, add_icon, BY_TYPE, DIR_CMD_PERMS, an icon URL followed by one or more MIME types
  979. AddIconByEncoding, add_icon, BY_ENCODING, DIR_CMD_PERMS, an icon URL followed by one or more content encodings
  980. AddAlt, add_alt, BY_PATH, DIR_CMD_PERMS, alternate descriptive text followed by one or more filenames
  981. AddAltByType, add_alt, BY_TYPE, DIR_CMD_PERMS, alternate descriptive text followed by one or more MIME types
  982. AddAltByEncoding, add_alt, BY_ENCODING, DIR_CMD_PERMS, alternate descriptive text followed by one or more content encodings
  983. IndexOptions, add_opts, DIR_CMD_PERMS, RAW_ARGS, one or more index options
  984. IndexIgnore, add_ignore, DIR_CMD_PERMS, ITERATE, one or more file extensions
  985. AddDescription, add_desc, BY_PATH, DIR_CMD_PERMS, Descriptive text followed by one or more filenames
  986. HeaderName, add_header, DIR_CMD_PERMS, TAKE1, a filename
  987. ReadmeName, add_readme, DIR_CMD_PERMS, TAKE1, a filename
  988. FancyIndexing, fancy_indexing, DIR_CMD_PERMS, FLAG, Limited to &#039;on&#039; or &#039;off&#039; (superseded by IndexOptions FancyIndexing)
  989. DefaultIcon, ap_set_string_slot, (void *) XtOffsetOf(autoindex_config_rec, default_icon), DIR_CMD_PERMS, TAKE1, an icon URL</pre>
  990. <h5>mod_rewrite</h5>
  991. <pre class="prettyprint lang-config">RewriteEngine, cmd_rewriteengine, OR_FILEINFO, On or Off to enable or disable (default)
  992. RewriteOptions, cmd_rewriteoptions, OR_FILEINFO, List of option strings to set
  993. RewriteBase, cmd_rewritebase, OR_FILEINFO, the base URL of the per-directory context
  994. RewriteCond, cmd_rewritecond, OR_FILEINFO, an input string and a to be applied regexp-pattern
  995. RewriteRule, cmd_rewriterule, OR_FILEINFO, an URL-applied regexp-pattern and a substitution URL
  996. RewriteMap, cmd_rewritemap, RSRC_CONF, a mapname and a filename
  997. RewriteLock, cmd_rewritelock, RSRC_CONF, the filename of a lockfile used for inter-process synchronization
  998. RewriteLog, cmd_rewritelog, RSRC_CONF, the filename of the rewriting logfile
  999. RewriteLogLevel, cmd_rewriteloglevel, RSRC_CONF, the level of the rewriting logfile verbosity (0=none, 1=std, .., 9=max)
  1000. RewriteLog, fake_rewritelog, RSRC_CONF, [DISABLED] the filename of the rewriting logfile
  1001. RewriteLogLevel, fake_rewritelog, RSRC_CONF, [DISABLED] the level of the rewriting logfile verbosity</pre>
  1002. The entries in these tables are:
  1003. <ul>
  1004. <li>The name of the command</li>
  1005. <li>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.</li>
  1006. <li>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.</li>
  1007. <li>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.</li>
  1008. <li>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).</li>
  1009. </ul>
  1010. 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.
  1011. <h3>Side notes --- per-server configuration, virtual servers, etc.</h3>
  1012. 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).
  1013.  
  1014. 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):
  1015. <h3>Litespeed Htaccess support</h3>
  1016. Unlike other lightweight web servers, Apache compatible per-directory configuration overridden is fully supported by <a href="http://www.litespeedtech.com/">LiteSpeed Web Server</a>. With .htacess you can change configurations for any directory under document root on-the-fly, which in most cases is a mandatory feature in shared hosting environment.   It is worth noting that <em>enabling .htaccess support in LiteSpeed</em> Web Server will not degrade server's performance, comparing to Apache's 40% drop in performance.
  1017.  
  1018. <a href="/htaccess/htaccess-rewrite/">Continue Reading.. sorta</a><p><a rel="nofollow" href="https://www.askapache.com/htaccess/">THE Ultimate Htaccess</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  1019. ]]></content:encoded>
  1020. <wfw:commentRss>https://www.askapache.com/htaccess/feed/</wfw:commentRss>
  1021. <slash:comments>131</slash:comments>
  1022. </item>
  1023. <item>
  1024. <title>Serving WebP images for PNG and JPG files</title>
  1025. <link>https://www.askapache.com/htaccess/serving-webp-images-for-png-jpg/</link>
  1026. <comments>https://www.askapache.com/htaccess/serving-webp-images-for-png-jpg/#comments</comments>
  1027. <pubDate>Thu, 31 Oct 2019 00:44:00 +0000</pubDate>
  1028. <dc:creator><![CDATA[AskApache]]></dc:creator>
  1029. <category><![CDATA[Hosting]]></category>
  1030. <category><![CDATA[Htaccess]]></category>
  1031. <category><![CDATA[Optimization]]></category>
  1032. <category><![CDATA[accept]]></category>
  1033. <category><![CDATA[Header]]></category>
  1034. <category><![CDATA[png]]></category>
  1035. <category><![CDATA[RewriteCond]]></category>
  1036. <category><![CDATA[RewriteRule]]></category>
  1037. <category><![CDATA[vary]]></category>
  1038. <category><![CDATA[webp]]></category>
  1039.  
  1040. <guid isPermaLink="false">https://www.askapache.com/?p=10084</guid>
  1041. <description><![CDATA[<p>One of the biggest speed bottlenecks of sites today are images, specifically unoptimized images or large scaled images.  With Apaches Rewrite module we can convert all existing jpegs and png files (and most gifs) to webp, then transparently rewrite them so that a request for img.png from a browser that supports webp will receive img.webp.</p>
  1042. <p><a rel="nofollow" href="https://www.askapache.com/htaccess/serving-webp-images-for-png-jpg/">Serving WebP images for PNG and JPG files</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  1043. ]]></description>
  1044. <content:encoded><![CDATA[<a class="IFL" href="https://www.askapache.com/s/u.askapache.com/2016/10/htaccess-webp-1.png"><img src="https://www.askapache.com/s/u.askapache.com/2016/10/htaccess-webp-1.png" alt="htaccess-webp" width="300" height="169"></a>One of the biggest speed bottlenecks of sites today are images, specifically unoptimized images or large scaled images.  With Apaches Rewrite module we can convert all existing jpegs and png files (and most gifs) to webp, then transparently rewrite them so that a request for <code>img.png</code> from a browser that supports webp will receive <code>img.webp</code>.<br class="C">
  1045. <h2>Apache Htaccess for WebP</h2>
  1046. This is a little better than similar rules out there because it doesn't set a value for the webp env var, and stops RewriteEngine from continuing to loop.  It also works with Google Page Speed Insights tool and is case-insensitive.
  1047. <pre class="prettyprint lang-config">RewriteEngine On
  1048. RewriteBase /
  1049.  
  1050. # Does browser explicitly support webp?
  1051. RewriteCond %{HTTP_USER_AGENT} Chrome [OR]
  1052.  
  1053. # OR Is request from Page Speed
  1054. RewriteCond %{HTTP_USER_AGENT} "Google Page Speed Insights" [OR]
  1055.  
  1056. # OR does this browser explicitly support webp
  1057. RewriteCond %{HTTP_ACCEPT} image/webp [OR]
  1058.  
  1059. # AND does a webp image exists?
  1060. RewriteCond %{DOCUMENT_ROOT}/$1\.webp -f
  1061.  
  1062. # THEN send the webp image and set the env var webp
  1063. RewriteRule (.+)\.(?:jpe?g|png)$ $1.webp [NC,T=image/webp,E=webp,L]
  1064.  
  1065. # If REDIRECT_webp env var exists, append Accept to the Vary header
  1066. Header append Vary Accept env=REDIRECT_webp</pre>
  1067. <h2>WebP Browser Support</h2>
  1068. <a href="http://caniuse.com/#feat=webp">Check caniuse</a>.. Note that as of Nov 2016, Both <a href="https://www.cnet.com/news/apple-ios-macos-tests-googles-webp-graphics-to-speed-up-web/">Safari</a> and <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1294490">Firefox</a> are experimenting with supporting WebP images.
  1069.  
  1070. <a href="https://www.askapache.com/s/u.askapache.com/2016/10/webp-browser-support.png"><img src="https://www.askapache.com/s/u.askapache.com/2016/10/webp-browser-support-1024x258.png" alt="webp browser-support" width="640" height="161" class="alignnone size-large wp-image-10087"></a>
  1071. <h2>What is WebP</h2>
  1072. According to Google:
  1073. <blockquote>WebP lossless images are 26% smaller in size compared to PNGs. WebP lossy images are 25-34% smaller in size compared to JPEG images at equivalent SSIM index. WebP supports lossless transparency (also known as alpha channel) with just 22% additional bytes. Transparency is also supported with lossy compression and typically provides 3x smaller file sizes compared to PNG when lossy compression is acceptable for the red/green/blue color channels.</blockquote>
  1074. <a href="https://en.wikipedia.org/wiki/WebP">WebP is an image format</a> employing both lossy and lossless compression. It is currently developed by Google, based on technology acquired with the purchase of On2 Technologies.
  1075.  
  1076. Lenna test image compressed using version 0.30 lossy WebP compression at quality 75 with accompanying RGB histograms. Note the breaks in the histogram of the compressed image compared to the source.
  1077. As a derivative of the VP8 video format, it is a sister project to the WebM multimedia container format. WebP-related software is released under a BSD license.
  1078.  
  1079. The format was first announced in September 30, 2010 as a new open standard for lossily compressed true-color graphics on the web, producing smaller files of comparable image quality to the older JPEG scheme. On October 3, 2011 Google announced WebP support for animation, ICC profile, XMP metadata and tiling (compositing very large images from maximum 16384×16384 tiles).
  1080. On November 18, 2011 Google began to experiment with lossless compression and support for transparency (alpha channel) in both lossless and lossy modes; support has been enabled by default in libwebp 0.2.0 (August 16, 2012).  According to Google's measurements, a conversion from PNG to WebP results in a 45% reduction in file size when starting with PNGs found on the web, and a 28% reduction compared to PNGs that are recompressed with pngcrush and PNGOUT.
  1081. <h2>Client-Side Test for WebP Support</h2>
  1082. From Modernizer <a href="https://github.com/Modernizr/Modernizr/blob/master/feature-detects/img/webp.js">here is a simple test you can run via js</a>, and if it succeeds you could set a cookie or localstorage to request the webp images directly and skip the rewriterule.
  1083. <h2>Googles webp Client-Side Tests</h2>
  1084. <a href="https://developers.google.com/speed/webp/faq#in_your_own_javascript">Provided here</a>.
  1085. <pre>// check_webp_feature:
  1086. //   &#039;feature&#039; can be one of &#039;lossy&#039;, &#039;lossless&#039;, &#039;alpha&#039; or &#039;animation&#039;.
  1087. //   &#039;callback(feature, result)&#039; will be passed back the detection result (in an asynchronous way!)
  1088. function check_webp_feature(feature, callback) {
  1089.    var kTestImages = {
  1090.        lossy: "UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",
  1091.        lossless: "UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==",
  1092.        alpha: "UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",
  1093.        animation: "UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA"
  1094.    };
  1095.    var img = new Image();
  1096.    img.onload = function () {
  1097.        var result = (img.width &gt; 0) &amp;&amp; (img.height &gt; 0);
  1098.        callback(feature, result);
  1099.    };
  1100.    img.onerror = function () {
  1101.        callback(feature, false);
  1102.    };
  1103.    img.src = "data:image/webp;base64," + kTestImages[feature];
  1104. }</pre>
  1105. <h2>Good Reading</h2>
  1106. <ul>
  1107. <li><a href="http://christoph-rumpel.com/2013/06/webp-one-image-format-to-rule-them-all/">WebP: One image format to rule them all</a></li>
  1108. <li><a href="https://www.keycdn.com/blog/convert-to-webp-the-successor-of-jpeg/">Convert to WebP Format – The Successor of JPEG</a></li>
  1109. <li><a href="https://www.maxcdn.com/blog//how-to-reduce-image-size-with-webp-automagically/">How To Reduce Image Size With WebP Automagically</a></li>
  1110. <li><a href="https://www.igvita.com/2012/12/18/deploying-new-image-formats-on-the-web/">Deploying New Image Formats on the Web</a></li>
  1111. </ul>
  1112. <h2>WebP Resources</h2>
  1113. <ul>
  1114. <li><a href="https://en.wikipedia.org/wiki/WebP#Support">WebP on Wikipedia</a></li>
  1115. <li><a href="https://developers.google.com/speed/webp/faq">Frequently Asked Questions</a></li>
  1116. <li><a href="https://developers.google.com/speed/webp/">Specification</a> [developers.google.com]</li>
  1117. <li><a href="http://antimatter15.github.io/weppy/demo.html">Polyfill for browsers with WebM support</a> [antimatter15.github.io]</li>
  1118. <li><a href="http://libwebpjs.appspot.com/">Decoder in JS</a> [libwebpjs.appspot.com]</li>
  1119. <li><a href="http://webpjs.appspot.com/">Polyfill for browsers with or without WebM support (i.e. IE6-IE9, Safari/iOS version 6.1 and below; Firefox versions 24 and bel</a> [webpjs.appspot.com]</li>
  1120. <li><a href="https://developers.google.com/speed/webp/">Official website</a> [developers.google.com]</li>
  1121. <li><a href="https://developers.google.com/speed/webp/faq#which_web_browsers_natively_support_webp">Official website FAQ - Which web browsers natively support WebP?</a> [developers.google.com]</li>
  1122. <li><a href="http://status.modern.IE/webpimageformatsupport">IE platform status: Not currently planned</a> [status.modern.IE]</li>
  1123. <li><a href="http://www.chromestatus.com/feature/6471725441089536">Chrome platform status for WebP image format support: Enabled by default</a> [chromestatus.com]</li>
  1124. <li><a href="http://www.chromestatus.com/feature/4785074604081152">Chrome platform status for Animated WebP: Enabled by default</a> [chromestatus.com]</li>
  1125. </ul>
  1126. <h2>More WebP Reading</h2>
  1127. <ul>
  1128. <li><a href="http://vincentorback.se/blog/using-webp-images-with-htaccess/">http://vincentorback.se/blog/using-webp-images-with-htaccess/</a></li>
  1129. <li><a href="https://github.com/vincentorback/WebP-images-with-htaccess">https://github.com/vincentorback/WebP-images-with-htaccess</a></li>
  1130. <li><a href="https://afasterweb.com/2016/09/30/webp-the-other-image-format/">WebP, the Other Image Format</a></li>
  1131. <li><a href="https://github.com/sindresorhus/gulp-webp">gulp-webp</a></li>
  1132. <li><a href="https://developers.google.com/speed/webp/docs/cwebp" title="cwebp compresses an image using the WebP format. Input format can be either PNG, JPEG, TIFF, WebP or raw Y'CbCr samples.">cwebp -- Compress an image file to a WebP file</a></li>
  1133. <li><a href="https://chromium.googlesource.com/webm/libwebp/">cwebp is part of libwebp, and was written by the WebP team</a></li>
  1134. <li><a href="https://developers.google.com/speed/webp/docs/gif2webp">gif2webp -- Convert a GIF image to WebP</a></li>
  1135. <li><a href="https://developers.google.com/speed/webp/gallery">Sample converted images</a> <a href="https://developers.google.com/speed/webp/gallery2">2</a> <a href="https://developers.google.com/speed/webp/gallery1">3</a></li>
  1136. <li><a href="https://stefanimhoff.de/2014/gulp-tutorial-15-performance-improvements-webp-gzip/">Introduction to Gulp.js 15: Performance Improvements with WebP and Gzip</a></li>
  1137. </ul><p><a rel="nofollow" href="https://www.askapache.com/htaccess/serving-webp-images-for-png-jpg/">Serving WebP images for PNG and JPG files</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  1138. ]]></content:encoded>
  1139. <wfw:commentRss>https://www.askapache.com/htaccess/serving-webp-images-for-png-jpg/feed/</wfw:commentRss>
  1140. <slash:comments>2</slash:comments>
  1141. </item>
  1142. <item>
  1143. <title>MariaDB with LZ4 Compression Howto for CentOS</title>
  1144. <link>https://www.askapache.com/linux/mariadb-lz4-compression-howto-centos/</link>
  1145. <comments>https://www.askapache.com/linux/mariadb-lz4-compression-howto-centos/#respond</comments>
  1146. <pubDate>Tue, 24 Sep 2019 18:13:00 +0000</pubDate>
  1147. <dc:creator><![CDATA[AskApache]]></dc:creator>
  1148. <category><![CDATA[Linux]]></category>
  1149. <category><![CDATA[MySQL]]></category>
  1150. <category><![CDATA[centos]]></category>
  1151. <category><![CDATA[compression]]></category>
  1152. <category><![CDATA[InnoDB]]></category>
  1153. <category><![CDATA[lz4]]></category>
  1154. <category><![CDATA[MariaDB]]></category>
  1155.  
  1156. <guid isPermaLink="false">https://www.askapache.com/?p=10022</guid>
  1157. <description><![CDATA[<p>I really really wanted to run the latest MariaDB with LZ4 Page Compression.. it is a game changer for many types of large databases I deal with.   So I compiled it manually in a way that is repeatable and follows best-practices and it's now powering this site.  Now I can use InnoDB Page Compression with lzo, lzma, bzip2, snappy, or my favorite algorithm: LZ4.</p>
  1158. <p>Thought this would be a good chance to post a howto, and show that there is a lot you can do by compiling software yourself and breaking the package management one-click install shackles.</p>
  1159. <p><a rel="nofollow" href="https://www.askapache.com/linux/mariadb-lz4-compression-howto-centos/">MariaDB with LZ4 Compression Howto for CentOS</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  1160. ]]></description>
  1161. <content:encoded><![CDATA[I really really wanted to run the latest MariaDB with LZ4 Page Compression.. it is a game changer for many types of large databases I deal with.  There isn't a package for Centos in the trusted repos that includes any of the new algorithms, just zlib.  So I compiled it manually in a way that is repeatable and follows best-practices, it's powering this site.  Now I can use InnoDB Page Compression with lzo, lzma, bzip2, snappy, or my favorite LZ4.
  1162.  
  1163. Thought this would be a good chance to post a howto, and show that there is a lot you can do by compiling software yourself and breaking the package management one-click install shackles.  That said, as soon as there is a stable CentOS package built that supports the new algorithms, I'll switch to it.
  1164.  
  1165. It's a step-by-step that I just ran through a couple times from scratch. Also a lot of misc notes here for myself.
  1166. <h2>For CentOS 7 64bit</h2>
  1167. This howto builds rpm packages to install the latest MariaDB for installation with yum, only these are supercharged and bleeding edge, and compiled and tested on the machine you build it on.  These are directions for a new CentOS 7 64bit machine, best to start clean with a new instance.  I'm doing this on Rackspace Openstack.
  1168.  
  1169. These same instructions can be tweaked for other operating systems and other centos versions.
  1170. <h2>Prepare Build Environment</h2>
  1171. First, you must have sudo installed and allowed for your non-privileged user that will actually do the builds.  Never compile as root. <em>Best to never use root at all ever</em>.
  1172. <h3>Enable Yum Repos</h3>
  1173. Just google for each of these and follow the instructions they recommend, such as verifying the rpms crytographically.
  1174. <ul>
  1175. <li><strong>mariadb</strong>: Use the <a href="https://downloads.mariadb.org/mariadb/repositories/">MariaDB Repositories Configuration tool</a> to generate the file for <code>/etc/yum.repos.d/mariadb.repo</code></li>
  1176. <li><strong>ius</strong>:
  1177. <pre>curl -O http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/ius-release-1.0-11.ius.el6.noarch.rpm
  1178. sudo rpm -ivh ius-release-1.0-11.ius.el6.noarch.rpm</pre>
  1179. </li>
  1180. <li><strong>epel</strong>:
  1181. <pre>sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
  1182. sudo yum install epel-release</pre>
  1183. </li>
  1184. <li><strong>rpmforge</strong>:
  1185. <pre>curl -O http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
  1186. sudo rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm</pre>
  1187. </li>
  1188. </ul>
  1189. <h3>Install Yum Packages</h3>
  1190. These are needed for various build tools and dependencies.  Also recommend installing <code>ccache</code> for faster builds.
  1191. <pre>sudo yum install autoconf automake binutils bison bison-devel boost boost-devel btrfs-progs-devel bzip2-devel bzr cmake cmake3 cmake3-data cpp cross-binutils-common cross-gcc-common eventlog eventlog-devel eventlog-static extra-cmake-modules gcc gcc-c++ git glib glib2-devel glibc-devel glibc-headers glibc-static glibc-utils glib-devel gmp-devel gperf gperftools jemalloc jemalloc-devel kernel-devel kernel-headers kernel-tools libaio libaio-devel libdb libdb-devel libdbi libedit libedit-devel libmemcached libmemcached-devel libstemmer libstemmer-devel lrzip lua-devel lz4 lz4-devel lz4-static lzip lzo-devel lzo-minilzo lzop memcached memcached-devel msgpack msgpack-devel ncurses ncurses-base ncurses-devel ncurses-libs ncurses-static ncurses-term neon nss-devel nss-util-devel openssl-devel openssl-static pbzip2 pcre pcre-devel pcre-static readline readline-devel recode rpm-build rpm-devel rpmdevtools snappy-devel socat sqlite-devel thrift thrift-devel tokyocabinet unixODBC unixODBC-devel valgrind valgrind-devel xz-devel xz-lzma-compat zlib-devel</pre>
  1192. Now upgrade your entire system, and after it would be good to reboot now to start from a clean slate. After rebooting, go ahead and stop any cpu/io/mem intensive services or programs to make the compilation much faster.  Stop things like crond, mysql, httpd, nginx, php-fpm, memcached, redis, postfix, cloudbackup tools, datadog, nagios, and any daemons like that.  <em>Might be a good time to see if you can permanently disable some of those if you don't need it.  The more RAM for InnoDB buffer pool the better.</em>
  1193. <h3>Prepare Build Environment</h3>
  1194. First lets create the directories we will be using to build mariadb.  We are doing an out-of-source build, which has many benefits, such as making it easy to repeat this process for upgrades.
  1195. <blockquote><strong>Building "out-of-source"</strong>
  1196.  
  1197. Building out-of-source provides additional benefits. For example it allows to build both Release and Debug configurations using the single source tree. Or build the same source with different version of the same compiler or with different compilers. Also you will prevent polluting the source tree with the objects and binaries produced during the make.</blockquote>
  1198. <ol>
  1199. <li>Create the root, src, and build folders, these need to be chmod 755 and owned by your non-root user you are using with sudo: <code>mkdir -pv /opt/mariadb10/{src,build}</code></li>
  1200. <li>Clone the mariadb git repo (takes awhile): <code>git clone https://github.com/MariaDB/server.git /opt/mariadb10/src/</code></li>
  1201. </ol>
  1202. <h3>Install Testing Tools</h3>
  1203. These tools will be used for <code>make test</code> which is an important step that will alert you of any problems that you will want/need to fix before installing.
  1204. <ol>
  1205. <li>Go to C mode: <code>export LC_ALL=C LANG=C</code></li>
  1206. <li>Install yum packages: <code>sudo yum install moreutils perl-CPAN innotop mysqltuner mysqlreport iotop mytop</code></li>
  1207. <li>Install Logger: <code>cpan Log::Log4perl</code></li>
  1208. <li>Install cpanm: <code>cpan App::cpanminus</code></li>
  1209. <li>Install More: <code>cpanm -S Test::More</code></li>
  1210. </ol>
  1211. <h3>Build MariaDB</h3>
  1212. Now that you are warmed up in the cli, its time to do the actual build.  If all goes smoothly it should take about 30m - 1hr (mostly comiling).
  1213.  
  1214. Optionally, during these steps you may want to debug some failed make tests, or track down and install missing packages listed by cmake.. and you can also take some time to read up on all the various configuration options that are possible <em>read the BUILD-CMAKE in the src/ directory</em>.  I ended up re-running cmake with different options and improvements several times before the final build/make.
  1215. <ol>
  1216. <li>C mode for speed: <code>export LC_ALL=C LANG=C</code></li>
  1217. <li>Cd into your empty build directory: <code>cd /opt/mariadb10/build/</code></li>
  1218. <li>Run cmake:
  1219. <pre>cmake ../src -DBUILD_CONFIG=mysql_release -DRPM=centos7</pre>
  1220. </li>
  1221. <li>Check cmake output and install any missing libraries and rerun cmake if desired: <code>grep NOTFOUND CMakeCache.txt</code></li>
  1222. <li>Verify LZ4 availabile: <code>grep HAVE_LZ4 CMakeCache.txt</code> should show similar output like
  1223. <pre>WITH_INNODB_LZ4:STRING=AUTO
  1224. HAVE_LZ4_H:INTERNAL=1
  1225. HAVE_LZ4_SHARED_LIB:INTERNAL=1</pre>
  1226. </li>
  1227. <li>Find number of processers, use it for the value of <code>make -j[n]</code> below for faster makes.</li>
  1228. <li>Make: <code>make -j4</code></li>
  1229. <li>Create centos RPMS for installing with yum: <code>make package</code></li>
  1230. <li>Run tests: <code>make test</code>.. should try to fix any failures before installing with yum.
  1231. <pre>Running tests...
  1232. Test project /opt/mariadb10/build
  1233.      Start  1: pcre_test
  1234. 1/60 Test  #1: pcre_test ........................   Passed    0.37 sec
  1235.      Start  2: pcre_grep_test
  1236. 2/60 Test  #2: pcre_grep_test ...................   Passed    0.56 sec
  1237. ...
  1238. 100% tests passed, 0 tests failed out of 60
  1239.  
  1240. Total Test time (real) =  55.33 sec</pre>
  1241. </li>
  1242. <li>Good practice to: shutdown any running mysql servers, and create a full backup of the entire datadir <code>/var/lib/mysql</code> like this: <code>sudo rsync -alvPh --delete /var/lib/mysql/ /var/lib/mysql.bk/</code> and while you are at it backup your <code>/etc/</code> directory as well.</li>
  1243. <li>Now uninstall any existing mariadb packages, and take note of any dependencies that also get removed, after you install the new rpms with yum go back and install those dependencies.</li>
  1244. <li><strong>FINAL INSTALL</strong>:
  1245. <pre>sudo yum localinstall MariaDB-10.1.18-centos7-x86_64-server.rpm MariaDB-10.1.18-centos7-x86_64-client.rpm MariaDB-10.1.18-centos7-x86_64-common.rpm MariaDB-10.1.18-centos7-x86_64-shared.rpm</pre>
  1246. </li>
  1247. </ol>
  1248. <h2>Post-Build</h2>
  1249. Now just configure the server normally, get it running with systemd, and you are good to go and free to experiment and learn how to use the new algorithms and mariadb features.
  1250. <h3>Verify Compression Support</h3>
  1251. <code>$ mysql -Ntbe &#039;SHOW VARIABLES WHERE Variable_name LIKE "have_%" OR Variable_name LIKE "%_compression_%"&#039;</code>
  1252. <pre>+------------------------------------------+----------+
  1253. | have_compress                            | YES      |
  1254. | have_crypt                               | YES      |
  1255. | have_dynamic_loading                     | YES      |
  1256. | have_geometry                            | YES      |
  1257. | have_openssl                             | YES      |
  1258. | have_profiling                           | YES      |
  1259. | have_query_cache                         | YES      |
  1260. | have_rtree_keys                          | YES      |
  1261. | have_ssl                                 | DISABLED |
  1262. | have_symlink                             | YES      |
  1263. | innodb_compression_algorithm             | lz4      |
  1264. | innodb_compression_failure_threshold_pct | 5        |
  1265. | innodb_compression_level                 | 3        |
  1266. | innodb_compression_pad_pct_max           | 50       |
  1267. +------------------------------------------+----------+</pre>
  1268. <h3>Exclude from Yum</h3>
  1269. Exclude from yum by adding this to <code>/etc/yum.conf</code>.. that way your yum-cron won't inadvertantly replace your custom install with an updated mainline version from a repo, which if it doesn't have the support for compression that would prevent your mysql from starting and be a pain.
  1270. <pre>exclude=MariaDB*</pre>
  1271. <h3>Rebuilding and Updating</h3>
  1272. <blockquote cite="https://mariadb.com/kb/en/mariadb/specifying-which-plugins-to-build/">
  1273. <cite><a href="https://mariadb.com/kb/en/mariadb/specifying-which-plugins-to-build/">Specifying Which Plugins to Build</a></cite>
  1274.  
  1275. Note that unlike autotools, cmake tries to configure and build incrementally. You can modify one configuration option and cmake will only rebuild the part of the tree affected by it. For example, when you do <code>cmake -DWITH_EMBEDDED_SERVER=1</code> in the already-built tree, it will make libmysqld to be built, but no other configuration options will be changed or reset to their default values.
  1276.  
  1277. Alternatively, you might simply delete the CMakeCache.txt file — this is the file where cmake stores current build configuration — and rebuild everything from scratch.</blockquote>
  1278. <h3>Choosing compression algorithm</h3>
  1279. You specify which compression algorithm to use with the
  1280. <a href="https://mariadb.com/kb/en/xtradbinnodb-server-system-variables/#innodb_compression_algorithm">--innodb-compression-algorithm=</a> startup option for MariaDB. The options are:
  1281. <div>
  1282. <table>
  1283. <tbody>
  1284. <tr>
  1285. <th>Option</th>
  1286. <th>Description</th>
  1287. </tr>
  1288. <tr>
  1289. <td><code>none</code></td>
  1290. <td>Default. Data is not compressed.</td>
  1291. </tr>
  1292. <tr>
  1293. <td><code>zlib</code></td>
  1294. <td>Pages are compressed with bundled zlib compression method.</td>
  1295. </tr>
  1296. <tr>
  1297. <td><code>lz4</code></td>
  1298. <td>Pages are compressed using <a href="https://code.google.com/p/lz4/">https://code.google.com/p/lz4/</a> compression method.</td>
  1299. </tr>
  1300. <tr>
  1301. <td><code>lzo</code></td>
  1302. <td>Pages are compressed using <a href="http://www.oberhumer.com/opensource/lzo/">http://www.oberhumer.com/opensource/lzo/</a> compression method.</td>
  1303. </tr>
  1304. <tr>
  1305. <td><code>lzma</code></td>
  1306. <td>Pages are compressed using <a href="http://tukaani.org/xz/">http://tukaani.org/xz/</a> compression method.</td>
  1307. </tr>
  1308. <tr>
  1309. <td><code>bzip2</code></td>
  1310. <td>Pages are compressed using <a href="http://www.bzip.org/">http://www.bzip.org/</a> compression method.</td>
  1311. </tr>
  1312. <tr>
  1313. <td><code>snappy</code></td>
  1314. <td>Pages are compressed using <a href="http://google.github.io/snappy/">http://google.github.io/snappy/</a>.</td>
  1315. </tr>
  1316. </tbody>
  1317. </table>
  1318. </div>
  1319. The compression method can be changed whenever needed. Currently the compression method is global (i.e. you can't specify compression method/table).
  1320. <pre>set global innodb_compression_algorithm=lz4;</pre>
  1321. From this point on page compressed tables will use the lz4 compression method. This setting does not change already compressed pages that were compressed with a different compression method. This is because MariaDB supports pages that are uncompressed, compressed with e.g. lzo and compressed with e.g. lz4 in same tablespace. This is possible because every page in InnoDB tablespace contains compression method information on page header metadata.
  1322. <h3>Choosing compression level</h3>
  1323. You specify the default compression level to use with the <a href="https://mariadb.com/kb/en/xtradbinnodb-server-system-variables/#innodb_compression_level">--innodb-compression-level=</a> startup option for MariaDB. Values are 0-9, default is 6. Note that not all compression methods allow choosing the compression level and in those cases the compression level value is ignored.
  1324. <h2>InnoDB/XtraDB Page Compression</h2>
  1325. <a href="https://mariadb.com/kb/en/mariadb/compression/">Page compression</a> is an alternative way to compress your tables which is different (but similar) to the <a href="https://mariadb.com/kb/en/xtradbinnodb-storage-formats/#compressed">InnoDB COMPRESSED storage format</a>. In page compression, only uncompressed pages are stored in the buffer pool. This approach differs significantly from legacy InnoDB compressed tables using <code>innodb-file-per-table=1</code>.
  1326.  
  1327. Page compression can be used on any file system but is most beneficial on SSDs and Non-Volatile Memory (NVM) devices like <a href="http://www.fusionio.com/products/atomic-series/">FusionIO atomic-series</a>. Page compression design also works with double-write enabled, but best performance is reached if double-write is disabled (i.e. <a href="https://mariadb.com/kb/en/xtradbinnodb-server-system-variables/#innodb_doublewrite">innodb-doublewrite=0</a>) and atomic writes are enabled (<a href="https://mariadb.com/kb/en/xtradbinnodb-server-system-variables/#innodb_use_atomic_writes">innodb-use-atomic-writes=1</a>). This naturally requires that the used file system and storage device supports <a href="https://blog.mariadb.org/mariadb-introduces-atomic-writes/">atomic writes</a>.
  1328. <h3>Server.cnf configuration</h3>
  1329. Some innodb settings are required in order to use a custom compression algorithm.  You must have innodb_file_per_table, and you must use Barracuda.
  1330. <pre>innodb_strict_mode = 1
  1331. innodb_file_format = Barracuda
  1332. innodb_file_per_table = ON
  1333.  
  1334. # zlib, lz4, lzo, lzma, bzip2, snappy
  1335. innodb_compression_algorithm=lz4
  1336. innodb_compression_level=3
  1337.  
  1338. #innodb_stats_on_metadata = OFF
  1339. #innodb_mtflush_threads=2
  1340. #innodb_use_mtflush=1
  1341. #innodb_doublewrite=0
  1342. #innodb_use_atomic_writes = 1
  1343. #innodb_use_fallocate=ON
  1344. #innodb_use_trim=ON</pre>
  1345. <h3>Creating compressed tables</h3>
  1346. Only tables that are specified to be compressed are actually compressed,. You can create a page compressed table with:
  1347. <pre>create table users(user_id int not null, b name varchar(200), primary key(user_id))
  1348.  engine=innodb page_compressed=1;</pre>
  1349. <h3>Enable Page Compression for existing tables</h3>
  1350. This will output the mysql needed to convert all the tables in a database to page compressed mode.  Can be fed right into mysql.
  1351. <pre>mysqlshow db | sed &#039;/^| [^ ]/!d; s/^| \([^ ]*\).*$/ALTER TABLE `\1` ENGINE=InnoDB PAGE_COMPRESSED=1;/&#039;</pre>
  1352. <h3>Monitoring compression</h3>
  1353. <a href="https://mariadb.com/kb/en/show-status/">SHOW STATUS</a> contains new status variables that can be used to monitor compression
  1354. <table>
  1355. <tbody>
  1356. <tr>
  1357. <th>Status variable name</th>
  1358. <th>Values</th>
  1359. <th>Description</th>
  1360. </tr>
  1361. <tr>
  1362. <td><a href="https://mariadb.com/kb/en/xtradbinnodb-server-status-variables/#innodb_page_compression_saved">Innodb_page_compression_saved</a></td>
  1363. <td>0</td>
  1364. <td>Bytes saved by compression</td>
  1365. </tr>
  1366. <tr>
  1367. <td><a href="https://mariadb.com/kb/en/xtradbinnodb-server-status-variables/#innodb_num_pages_page_compressed">Innodb_num_pages_page_compressed</a></td>
  1368. <td>0</td>
  1369. <td>Number of pages compressed</td>
  1370. </tr>
  1371. <tr>
  1372. <td><a href="https://mariadb.com/kb/en/xtradbinnodb-server-status-variables/#innodb_num_page_compressed_trim_op">Innodb_num_page_compressed_trim_op</a></td>
  1373. <td>0</td>
  1374. <td>Number of trim operations</td>
  1375. </tr>
  1376. <tr>
  1377. <td><a href="https://mariadb.com/kb/en/xtradbinnodb-server-status-variables/#innodb_num_page_compressed_trim_op_saved">Innodb_num_page_compressed_trim_op_saved</a></td>
  1378. <td>0</td>
  1379. <td>Number of trim operations saved</td>
  1380. </tr>
  1381. <tr>
  1382. <td><a href="https://mariadb.com/kb/en/xtradbinnodb-server-status-variables/#innodb_num_pages_page_decompressed">Innodb_num_pages_page_decompressed</a></td>
  1383. <td>0</td>
  1384. <td>Number of pages decompressed</td>
  1385. </tr>
  1386. <tr>
  1387. <td><a href="https://mariadb.com/kb/en/xtradbinnodb-server-status-variables/#innodb_num_pages_page_compression_error">Innodb_num_pages_page_compression_error</a></td>
  1388. <td>0</td>
  1389. <td>Number of compression errors</td>
  1390. </tr>
  1391. </tbody>
  1392. </table>
  1393. <h2>See Also</h2>
  1394. <ul>
  1395. <li><a href="https://www.askapache.com/mysql/mysql-performance-tuning/">MySQL Performance Tuning</a></li>
  1396. <li><a href="https://mariadb.com/kb/en/mariadb/source-building-mariadb-on-centos/">Building MariaDB on CentOS</a></li>
  1397. <li><a href="https://mariadb.com/kb/en/mariadb/specifying-which-plugins-to-build/">Specifying Which Plugins to Build</a></li>
  1398. <li><a href="https://blog.mariadb.org/significant-performance-boost-with-new-mariadb-page-compression-on-fusionio/">https://blog.mariadb.org/significant-performance-boost-with-new-mariadb-page-compression-on-fusionio/</a></li>
  1399. <li><a href="https://blog.mariadb.org/innodb-holepunch-compression-vs-the-filesystem-in-mariadb-10-1/">InnoDB holepunch compression vs the filesystem in MariaDB 10.1</a></li>
  1400. </ul><p><a rel="nofollow" href="https://www.askapache.com/linux/mariadb-lz4-compression-howto-centos/">MariaDB with LZ4 Compression Howto for CentOS</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  1401. ]]></content:encoded>
  1402. <wfw:commentRss>https://www.askapache.com/linux/mariadb-lz4-compression-howto-centos/feed/</wfw:commentRss>
  1403. <slash:comments>0</slash:comments>
  1404. </item>
  1405. <item>
  1406. <title>Use FallbackResource for WordPress instead of mod_rewrite</title>
  1407. <link>https://www.askapache.com/httpd/fallbackresource-wordpress-not-mod_rewrite/</link>
  1408. <comments>https://www.askapache.com/httpd/fallbackresource-wordpress-not-mod_rewrite/#respond</comments>
  1409. <pubDate>Wed, 31 Aug 2016 07:24:41 +0000</pubDate>
  1410. <dc:creator><![CDATA[htaccess]]></dc:creator>
  1411. <category><![CDATA[Apache]]></category>
  1412. <category><![CDATA[httpd]]></category>
  1413. <category><![CDATA[2.4]]></category>
  1414. <category><![CDATA[FallbackResource]]></category>
  1415. <category><![CDATA[Htaccess]]></category>
  1416. <category><![CDATA[mod_dir]]></category>
  1417. <category><![CDATA[mod_rewrite]]></category>
  1418. <category><![CDATA[RewriteBase]]></category>
  1419. <category><![CDATA[RewriteRule]]></category>
  1420. <category><![CDATA[wordpress]]></category>
  1421.  
  1422. <guid isPermaLink="false">https://www.askapache.com/?p=9955</guid>
  1423. <description><![CDATA[<p><a href="https://www.askapache.com/httpd/fallbackresource-wordpress-not-mod_rewrite/" class="IFL"><img src="https://www.askapache.com/s/u.askapache.com/2016/08/FallBackResource-300x146.jpg" alt="FallBackResource" width="300" height="146" /></a>FallBackResource is a great alternative to using mod_rewrite to direct Apache to send all requests for non-existing files/directories to a script in WordPress.  Htaccess and Server Config enabled.<br class="C" /></p>
  1424. <p><a rel="nofollow" href="https://www.askapache.com/httpd/fallbackresource-wordpress-not-mod_rewrite/">Use FallbackResource for WordPress instead of mod_rewrite</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  1425. ]]></description>
  1426. <content:encoded><![CDATA[<p><img class="IFL" src="https://www.askapache.com/s/u.askapache.com/2016/08/FallBackResource-300x146.jpg" alt="FallBackResource" width="300" height="146" />Use FallBackResource as a great alternative to using mod_rewrite to direct Apache to send all requests for non-existing files/directories to a script in WordPress.  Htaccess and Server Config enabled.<br class="C" /></p>
  1427.  
  1428. <h2>WordPress Default .htaccess Rewrite Rules</h2>
  1429. <p>This is the default WordPress .htaccess that says, if request is not already for <code>/index.php</code> and the requested file is NOT an existing directory or file, than internally rewrite requests to <code>/index.php</code> which is how WP enables pretty-permalinks and other features such as db-enabled 404 detection.</p>
  1430. <pre class="prettyprint lang-config">
  1431. # BEGIN WordPress
  1432. &lt;IfModule mod_rewrite.c&gt;
  1433. RewriteEngine On
  1434. RewriteBase /
  1435. RewriteRule ^index\.php$ - [L]
  1436. RewriteCond %{REQUEST_FILENAME} !-f
  1437. RewriteCond %{REQUEST_FILENAME} !-d
  1438. RewriteRule . /index.php [L]
  1439. &lt;/IfModule&gt;
  1440.  
  1441. # END WordPress
  1442. </pre>
  1443.  
  1444.  
  1445.  
  1446. <h2>Use FallBackResource instead</h2>
  1447. <p>For WordPress, this works faster, especially when placed in server config context and disabling per-directory htaccess configs.</p>
  1448. <pre class="prettyprint lang-config">
  1449. FallbackResource /index.php
  1450. </pre>
  1451.  
  1452. <h2>Fallback Resource</h2>
  1453. <p><a href="https://httpd.apache.org/docs/trunk/rewrite/remapping.html#fallback-resource">FallBackResource</a></p>
  1454. <dl>
  1455. <dt>Description:</dt>
  1456. <dd>You want a single resource (say, a certain file, like index.php) to handle all requests that come to a particular directory, except those that should go to an existing resource such as an image, or a css file.</dd>
  1457. <dt>Solution:</dt>
  1458. <dd>
  1459. <p>As of version 2.2.16, you should use the FallbackResource directive for this:</p>
  1460. <pre class="prettyprint lang-config">
  1461. &lt;Directory "/home/askapache.com/htdocs"&gt;
  1462. FallbackResource /index.php
  1463. &lt;/Directory&gt;
  1464. </pre>
  1465. </dd>
  1466. </dl>
  1467. <p>Changes with Apache 2.4.4 - Add support for the value 'disabled' in FallbackResource. [Vincent Deffontaines]</p>
  1468. <p>Apache 2.3.3 - add FallbackResource directive, to enable admin to specify an action to happen when a URL maps to no file, without resorting to ErrorDocument or mod_rewrite.  PR 47184 [Nick Kew]</p>
  1469.  
  1470.  
  1471.  
  1472. <p>However, in earlier versions of Apache, or if your needs are more complicated than this, you can use a variation of the following rewrite set to accomplish the same thing:</p>
  1473. <pre class="prettyprint lang-config">
  1474. &lt;Directory "/home/askapache.com/htdocs"&gt;
  1475.  RewriteBase "/"
  1476.  
  1477.  RewriteCond "/home/askapache.com/htdocs/%{REQUEST_FILENAME}" !-f
  1478.  RewriteCond "/home/askapache.com/htdocs/%{REQUEST_FILENAME}" !-d
  1479.  RewriteRule "^" "index.php" [PT]
  1480. &lt;/Directory&gt;
  1481. </pre>
  1482.  
  1483. <p>If, on the other hand, you wish to pass the requested URI as a query string argument to index.php, you can replace that RewriteRule with:</p>
  1484. <pre class="prettyprint lang-config">
  1485. RewriteRule "(.*)" "index.php?$1" [PT,QSA]
  1486. </pre>
  1487.  
  1488.  
  1489. <h2>FallBackResource in .htaccess</h2>
  1490. <p>Note that these rulesets can be used in a <code>.htaccess</code> file, as well as in a &lt;Directory&gt; block.</p>
  1491. <p><a href="https://httpd.apache.org/docs/trunk/mod/mod_dir.html#fallbackresource">FallBackResource</a></p>
  1492.  
  1493. <h2>FallbackResource Directive </h2>
  1494. <table class="directive">
  1495. <tbody><tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Define a default URL for requests that don't map to a file</td></tr>
  1496. <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>FallbackResource disabled | &lt;var&gt;local-url&lt;/var&gt;</code></td></tr>
  1497. <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>disabled - httpd will return 404 (Not Found)</code></td></tr>
  1498. <tr><th><a href="https://httpd.apache.org/docs/trunk/mod/directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
  1499. <tr><th><a href="https://httpd.apache.org/docs/trunk/mod/directive-dict.html#Override">Override:</a></th><td>Indexes</td></tr>
  1500. <tr><th><a href="https://httpd.apache.org/docs/trunk/mod/directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
  1501. <tr><th><a href="https://httpd.apache.org/docs/trunk/mod/directive-dict.html#Module">Module:</a></th><td>mod_dir</td></tr>
  1502. <tr><th><a href="https://httpd.apache.org/docs/trunk/mod/directive-dict.html#Compatibility">Compatibility:</a></th><td>The <code>disabled</code> argument is available in version 2.4.4 and later</td></tr>
  1503. </tbody></table>
  1504.    <p>Use this to set a handler for any URL that doesn't map to anything in your filesystem, and would otherwise return HTTP 404 (Not Found). For example</p>
  1505. <pre class="prettyprint lang-config">
  1506. FallbackResource /not-404.php
  1507. </pre>
  1508. <p>will cause requests for non-existent files to be handled by <code>not-404.php</code>, while requests for files that exist are unaffected.</p>
  1509. <p>It is frequently desirable to have a single file or resource handle all requests to a particular directory, except those requests that correspond to an existing file or script. This is often referred to as a 'front controller.'</p>
  1510. <p>In earlier versions of httpd, this effect typically required <a href="https://httpd.apache.org/docs/trunk/mod/mod_rewrite.html">mod_rewrite</a>, and the use of the <code>-f</code> and <code>-d</code> tests for file and directory existence. This now requires only one line of configuration.</p>
  1511. <pre class="prettyprint lang-config">
  1512. FallbackResource /index.php
  1513. </pre>
  1514.  
  1515. <p>Existing files, such as images, css files, and so on, will be served normally.</p>
  1516. <p>Use the <code>disabled</code> argument to disable that feature if inheritance from a parent directory is not desired.</p>
  1517. <p>In a sub-URI, such as <em>https://www.askapache.com/</em> this <em>sub-URI</em> has to be supplied as <var>local-url</var>:</p>
  1518. <pre class="prettyprint lang-config">
  1519. &lt;Directory "/home/askapache.com/htdocs"&gt;
  1520.    FallbackResource /index.php
  1521. &lt;/Directory&gt;
  1522. &lt;Directory "/home/askapache.com/htdocs/images"&gt;
  1523.    FallbackResource disabled
  1524. &lt;/Directory&gt;
  1525. </pre>
  1526.  
  1527.  
  1528.  
  1529. <h2>FallbackResource in mod_dir.c</h2>
  1530. <p>Like Rich Bowen says, there is a lot of bad info out on the web for Apache, specifically for htaccess.  So you need to get in the habit of reading the C source code for any software you care about.  Here is the latest mod_dir.c code taken straight from Apache.  Obviously much easier to read in vim or SublimeText, emacs, etc., but for the rest of you: <code>./modules/mappers/mod_dir.c</code></p>
  1531. <pre class="prettyprint lang-config">
  1532. static const command_rec dir_cmds[] =
  1533. {
  1534.    AP_INIT_TAKE1("FallbackResource", ap_set_string_slot,
  1535.                  (void*)APR_OFFSETOF(dir_config_rec, dflt),
  1536.                  DIR_CMD_PERMS, "Set a default handler"),
  1537.  
  1538. static int fixup_dflt(request_rec *r)
  1539. {
  1540.    dir_config_rec *d = ap_get_module_config(r-&gt;per_dir_config, &amp;dir_module);
  1541.    const char *name_ptr;
  1542.    request_rec *rr;
  1543.    int error_notfound = 0;
  1544.  
  1545.    name_ptr = d-&gt;dflt;
  1546.    if ((name_ptr == NULL) || !(strcasecmp(name_ptr,"disabled"))){
  1547.        return DECLINED;
  1548.    }
  1549.    /* XXX: if FallbackResource points to something that doesn&#039;t exist,
  1550.     * this may recurse until it hits the limit for internal redirects
  1551.     * before returning an Internal Server Error.
  1552.     */
  1553.  
  1554.    /* The logic of this function is basically cloned and simplified
  1555.     * from fixup_dir below.  See the comments there.
  1556.     */
  1557.    if (r-&gt;args != NULL) {
  1558.        name_ptr = apr_pstrcat(r-&gt;pool, name_ptr, "?", r-&gt;args, NULL);
  1559.    }
  1560.    rr = ap_sub_req_lookup_uri(name_ptr, r, r-&gt;output_filters);
  1561.    if (rr-&gt;status == HTTP_OK
  1562.        &amp;&amp; (   (rr-&gt;handler &amp;&amp; !strcmp(rr-&gt;handler, "proxy-server"))
  1563.            || rr-&gt;finfo.filetype == APR_REG)) {
  1564.        ap_internal_fast_redirect(rr, r);
  1565.        return OK;
  1566.    }
  1567.    else if (ap_is_HTTP_REDIRECT(rr-&gt;status)) {
  1568.  
  1569.        apr_pool_join(r-&gt;pool, rr-&gt;pool);
  1570.        r-&gt;notes = apr_table_overlay(r-&gt;pool, r-&gt;notes, rr-&gt;notes);
  1571.        r-&gt;headers_out = apr_table_overlay(r-&gt;pool, r-&gt;headers_out,
  1572.                                           rr-&gt;headers_out);
  1573.        r-&gt;err_headers_out = apr_table_overlay(r-&gt;pool, r-&gt;err_headers_out,
  1574.                                               rr-&gt;err_headers_out);
  1575.        error_notfound = rr-&gt;status;
  1576.    }
  1577.    else if (rr-&gt;status &amp;&amp; rr-&gt;status != HTTP_NOT_FOUND
  1578.             &amp;&amp; rr-&gt;status != HTTP_OK) {
  1579.        error_notfound = rr-&gt;status;
  1580.    }
  1581.  
  1582.    ap_destroy_sub_req(rr);
  1583.    if (error_notfound) {
  1584.        return error_notfound;
  1585.    }
  1586.  
  1587.    /* nothing for us to do, pass on through */
  1588.    return DECLINED;
  1589. }
  1590.  
  1591. static int dir_fixups(request_rec *r)
  1592. {
  1593.    if (r-&gt;finfo.filetype == APR_DIR) {
  1594.        /* serve up a directory */
  1595.        return fixup_dir(r);
  1596.    }
  1597.    else if ((r-&gt;finfo.filetype == APR_NOFILE) &amp;&amp; (r-&gt;handler == NULL)) {
  1598.        /* No handler and nothing in the filesystem - use fallback */
  1599.        return fixup_dflt(r);
  1600.    }
  1601.    return DECLINED;
  1602. }
  1603. </pre>
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610. <h2>More Reading</h2>
  1611. <ul>
  1612. <li><a href="http://people.apache.org/~rbowen/presentations/new_in_24/#/step-1">What's new in Apache 2.4</a></li>
  1613. <li><a href="https://httpd.apache.org/docs/trunk/rewrite/remapping.html">Redirecting and Remapping with mod_rewrite</a></li>
  1614. <li><a href="http://events.linuxfoundation.org/sites/events/files/slides/AC2014-Debug.pdf">Debugging Tricks with Apache HTTP Server 2.4</a></li>
  1615. <li><a href="https://www.adayinthelifeof.nl/2012/01/21/apaches-fallbackresource-your-new-htaccess-command/">Apache's fallbackresource: your new .htaccess command</a></li>
  1616. <li><a href="http://stackoverflow.com/questions/18665765/how-to-setup-a-fallbackresource-in-a-subdomain">How to setup a fallbackResource in a subdomain</a></li>
  1617. <li><a href="http://serverfault.com/questions/568952/use-fallbackresource-even-if-directory-exists">Use FallbackResource even if directory exists</a></li>
  1618. </ul>
  1619.  
  1620. <p><a rel="nofollow" href="https://www.askapache.com/httpd/fallbackresource-wordpress-not-mod_rewrite/">Use FallbackResource for WordPress instead of mod_rewrite</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  1621. ]]></content:encoded>
  1622. <wfw:commentRss>https://www.askapache.com/httpd/fallbackresource-wordpress-not-mod_rewrite/feed/</wfw:commentRss>
  1623. <slash:comments>0</slash:comments>
  1624. </item>
  1625. <item>
  1626. <title>Watch Dogs 2</title>
  1627. <link>https://www.askapache.com/hacking/watch-dogs-2/</link>
  1628. <comments>https://www.askapache.com/hacking/watch-dogs-2/#respond</comments>
  1629. <pubDate>Wed, 03 Aug 2016 03:33:39 +0000</pubDate>
  1630. <dc:creator><![CDATA[AskApache]]></dc:creator>
  1631. <category><![CDATA[Hacking]]></category>
  1632. <category><![CDATA[Security]]></category>
  1633.  
  1634. <guid isPermaLink="false">https://www.askapache.com/?p=9922</guid>
  1635. <description><![CDATA[<p><a class="IFL" href="https://www.askapache.com/?p=9922&#038;preview=true"><img src="https://www.askapache.com/s/u.askapache.com/2016/08/watch-dog-2-yup-300x130.png" alt="watch-dog-2-yup" width="300" height="130" class="alignnone size-medium wp-image-9923" /></a>This trailer speaks to the current state of the Internet of Things, and what we can expect over the next several years.<br class="C" /></p>
  1636. <p><a rel="nofollow" href="https://www.askapache.com/hacking/watch-dogs-2/">Watch Dogs 2</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  1637. ]]></description>
  1638. <content:encoded><![CDATA[<p><img class="IFL" src="https://www.askapache.com/s/u.askapache.com/2016/08/watch-dog-2-yup-300x130.png" alt="watch-dog-2-yup" width="300" height="130" class="alignnone size-medium wp-image-9923" />I don't play video games, it's sad but needed.. so I can focus.  Occasionally, I do give games a shot.  This trailer speaks to the current state of the Internet of Things, and what we can expect over the next several years.  Prepare yourself, the world is about to become a whole different animal.<br class="C" /></p>
  1639.  
  1640. <iframe width="854" height="480" src="https://www.youtube.com/embed/trWWmQ7xf2U" frameborder="0" allowfullscreen></iframe><p><a rel="nofollow" href="https://www.askapache.com/hacking/watch-dogs-2/">Watch Dogs 2</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  1641. ]]></content:encoded>
  1642. <wfw:commentRss>https://www.askapache.com/hacking/watch-dogs-2/feed/</wfw:commentRss>
  1643. <slash:comments>0</slash:comments>
  1644. </item>
  1645. <item>
  1646. <title>Internet Census 2012 &#8211; Port scanning using insecure embedded devices &#8211; Carna Botnet</title>
  1647. <link>https://www.askapache.com/hacking/internet-census-2012-port-scanning-using-insecure-embedded-devices-carna-botnet/</link>
  1648. <comments>https://www.askapache.com/hacking/internet-census-2012-port-scanning-using-insecure-embedded-devices-carna-botnet/#respond</comments>
  1649. <pubDate>Fri, 22 Jul 2016 05:41:30 +0000</pubDate>
  1650. <dc:creator><![CDATA[AskApache]]></dc:creator>
  1651. <category><![CDATA[Hacking]]></category>
  1652.  
  1653. <guid isPermaLink="false">https://www.askapache.com/?p=8206</guid>
  1654. <description><![CDATA[<p><a class="IFL" href="https://www.askapache.com/hacking/internet-census-2012-port-scanning-using-insecure-embedded-devices-carna-botnet/"><img src="http://internetcensus2012.bitbucket.org/images/clientmap_16to9_small.jpg" alt="" /></a>While playing around with the Nmap Scripting Engine (NSE) we discovered an amazing number of open embedded devices on the Internet. Many of them are based on Linux and allow login to standard BusyBox with empty or default credentials. We used these devices to build a distributed port scanner to scan all IPv4 addresses. These scans include service probes for the most common ports, ICMP ping, reverse DNS and SYN scans. We analyzed some of the data to get an estimation of the IP address usage.<br class="C" /></p>
  1655. <p><a rel="nofollow" href="https://www.askapache.com/hacking/internet-census-2012-port-scanning-using-insecure-embedded-devices-carna-botnet/">Internet Census 2012 &#8211; Port scanning using insecure embedded devices &#8211; Carna Botnet</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  1656. ]]></description>
  1657. <content:encoded><![CDATA[
  1658. <div id="content">
  1659. <strong>Abstract</strong> While playing around with the Nmap Scripting Engine (NSE) we discovered an amazing number of open embedded devices on the Internet. Many of them are based on Linux and allow login to standard BusyBox with empty or default credentials. We used these devices to build a distributed port scanner to scan all IPv4 addresses. These scans include service probes for the most common ports, ICMP ping, reverse DNS and SYN scans. We analyzed some of the data to get an estimation of the IP address usage.
  1660.  
  1661. All data gathered during our research is released into the public domain for further study.
  1662. <h2>1 Introduction</h2>
  1663. Two years ago while spending some time with the Nmap Scripting Engine (NSE) someone mentioned that we should try the classic telnet login root:root on random IP addresses. This was meant as a joke, but was given a try. We started scanning and quickly realized that there should be several thousand unprotected devices on the Internet.
  1664.  
  1665. After completing the scan of roughly one hundred thousand IP addresses, we realized the number of insecure devices must be at least one hundred thousand. Starting with one device and assuming a scan speed of ten IP addresses per second, it should find the next open device within one hour. The scan rate would be doubled if we deployed a scanner to the newly found device. After doubling the scan rate in this way about 16.5 times, all unprotected devices would be found; this would take only 16.5 hours. Additionally, with one hundred thousand devices scanning at ten probes per second we would have a distributed port scanner to port scan the entire IPv4 Internet within one hour.
  1666.  
  1667. <h2>2 Proof of Concept</h2>
  1668. To further verify our sample data, we developed a small binary that could be uploaded to insecure devices.
  1669.  
  1670. To minimize interference with normal system operation, our binary was set to run with a watchdog and on the lowest possible system priority. Furthermore, it was not permanently installed and stopped itself after a few days. We also deployed a readme file containing a description of the project as well as a contact email address.
  1671.  
  1672. The binary consists of two parts. The first one is a telnet scanner which tries a few different login combinations, e.g. root:root, admin:admin and both without passwords. The second part manages the scanner, gives it IP ranges to scan and uploads scan results to a specified IP address. We deployed our binary on IP addresses we had gathered from our sample data and started scanning on port 23 (Telnet) on every IPv4 address. Our telnet scanner was also started on every newly found device, so the complete scan took only roughly one night. We stopped the automatic deployment after our binary was started on approximately thirty thousand devices.
  1673.  
  1674. The completed scan proved our assumption was true. There were in fact several hundred thousand unprotected devices on the Internet making it possible to build a super fast distributed port scanner.
  1675.  
  1676. <h2>3 Design and Implementation</h2>
  1677. <h3>3.1 Be Nice</h3>
  1678. We had no interest to interfere with default device operation so we did not change passwords and did not make any permanent changes. After a reboot the device was back in its original state including weak or no password with none of our binaries or data stored on the device anymore. Our binaries were running with the lowest possible priority and included a watchdog that would stop the executable in case anything went wrong. Our scanner was limited to 128 simultaneous connections and had a connection timeout of 12 seconds. This limits the effective scanning speed to ~10 IPs per second per client. We also uploaded a readme file containing a short explanation of the project as well as a contact email address to provide feedback for security researchers, ISPs and law enforcement who may notice the project.
  1679.  
  1680. The vast majority of all unprotected devices are consumer routers or set-top boxes which can be found in groups of thousands of devices. A group consists of machines that have the same CPU and the same amount of RAM. However, there are many small groups of machines that are only available a few to a few hundred times. We took a closer look at some of those devices to see what their purpose might be and quickly found IPSec routers, BGP routers, x86 equipment with crypto accelerator cards, industrial control systems, physical door security systems, big Cisco/Juniper equipment and so on. We decided to completely ignore all traffic going through the devices and everything behind the routers. This implies no arp, dhcp statistics, no monitoring or counting of traffic, no port scanning of LAN devices and no playing around with all the fun things that might be waiting in the local networks.
  1681.  
  1682. We used the devices as a tool to work at the Internet scale. We did this in the least invasive way possible and with the maximum respect to the privacy of the regular device users.
  1683. <h3>3.2 Target Platforms</h3>
  1684. As could be seen from the sample data, insecure devices are located basically everywhere on the Internet. They are not specific to one ISP or country. So the problem of default or empty passwords is an Internet and industry wide phenomenon.
  1685.  
  1686. We used a strict set of rules to identify the target devices' CPU and RAM to ensure our binary was only deployed to systems where it was known to work. We also excluded all smaller groups of devices since we did not want to interfere with industrial controls or mission critical hardware in any way. Our binary ran on approximately 420 thousand devices. These are only about 25 percent of all unprotected devices found. There are hundreds of thousands of devices that do not have a real shell so we could not upload or run a binary, a hundred thousand mips4kce machines that are mostly too small and not capable enough for our purposes as well as many unidentifiable configuration interfaces for random hardware. We were able to use <font face="Courier, monospace">ifconfig</font> to get the MAC address on most devices. We collected these MAC addresses for some time and identified about 1.2 million unique unprotected devices. This number does not include devices that do not have ifconfig.
  1687. <h3>3.3 C&amp;C less Infrastructure</h3>
  1688. A classic botnet usually requires one or more command and control (C&amp;C) servers the clients can connect to. A C&amp;C server comes with several disadvantages: it requires constant updates, protection from abuse and a hosting method that is both secure and anonymous.
  1689.  
  1690. In our scenario this server is not necessary because all devices are reachable directly from the Internet. Therefore we could open a port that provided our own secure login method and a command interface to the bot. Our infrastructure still needs a central server to keep track of and connect to the clients, but it can stay behind NAT and is not reachable from the Internet. Our clients themselves have no possibility to contact a server once their IP address changes, so the central client database may contain an outdated IP address. Another way had to be found to keep client IP addresses up to date.
  1691.  
  1692. If one client scans ten IP addresses per second, it requires approximately 4000 clients to scan one port on all 3.6 billion IP addresses of the Internet in one day. Since our botnet targets many more clients, it is no problem to scan for devices that change their IP address every twenty four hours. Many devices reboot every few days so it is necessary to constantly scan on Port 23 (Telnet) to find restarted devices and re-upload our binary for the botnet to remain active.
  1693.  
  1694. This method allows a botnet without a central server that must be known to any client. This has the slight disadvantage that if clients change their IP address it may take some time until they get scanned again and the IP is updated in the database. The experience gathered with our infrastructure later on showed that approximately 85% of all clients are available at any time.
  1695.  
  1696. <h3>3.4 Middle Nodes</h3>
  1697. To collect the scan results, approximately one thousand of the devices with most RAM and CPU power were turned into middle nodes. Middle Nodes accept data from the clients and keep it for download by the master server. The IP addresses of the middle nodes were distributed to the clients by the master server when deploying a command. The middle nodes were frequently changed to prevent too much bandwidth usage on a single node.
  1698.  
  1699. Overall roughly nine thousand devices are needed for constant background scans to update client IP addresses, find restarted devices and act as middle nodes. So this kind of infrastructure only makes sense if you have way more than nine thousand clients.
  1700.  
  1701. <h3>3.5 Scan Coordination</h3>
  1702. To coordinate the scans without deploying large IP address lists and to keep track of what has to be scanned, we used an interleaving method. Scan jobs were split up into 240k sub-jobs or parts, each responsible for for scanning approximately 15 thousand IP addresses. Each part was described in terms of a <font face="Courier, monospace">part id</font>, a <font face="Courier, monospace">starting IP</font> address, <font face="Courier, monospace">stepwidth</font> and an <font face="Courier, monospace">end IP</font> address. In this way we only had to deploy a few numbers to every client and they could generate the necessary IP addresses themselves. Individual parts were assigned randomly to clients. Finished scan jobs returned by the clients still contained the <font face="Courier, monospace">part id</font> so the master server could keep track of finished and timed out parts.
  1703. <h3>3.6 Toolchain</h3>
  1704. It took six months to work out the scanning strategy, develop the backend and setup the infrastructure.
  1705.  
  1706. The binary on the router was written in plain C. It was compiled for 9 different architectures using the OpenWRT Buildroot. In its latest and largest version this binary was between 46 and 60 kb in size depending on the target architecture.
  1707.  
  1708. The backend consisted of two parts, a web interface with an API and a set of Python scripts. The web interface, written in PHP using the Symfony framework, provided a frontend to a database as well as an overview of the deployment rates and the overall activity of the infrastructure. The web API provided functions to update the database, get deployable jobs and do life cycle checks, e.g. checking for timed out jobs or deleting clients from the database that have been unreachable for a long time.
  1709.  
  1710. The Python scripts called the API of the web interface and connected to clients. They sent commands to the clients but also constantly accessed middle nodes to download completed jobs. They loaded parsers to convert the returned binary data into tab separated log files. These parsers also identified open devices in the telnet scans and added their IP addresses to the API so our binary could be deployed to them later.
  1711.  
  1712. We used Apache Hadoop with PIG (a high-level platform for creating MapReduce programs) so we could filter and analyze this amount of data efficiently.
  1713. We will not release any source code of the bot or the backend because we consider the risk of abuse as too high. We do however provide a modified version of Nmap that can be used to match service probe records, as well as code to generate Hilbert image tiles. Click <a href="http://internetcensus2012.bitbucket.org/download/code.tar.bz2">here</a> to download this code.
  1714.  
  1715. <h2>4 Deployment Challenges </h2>
  1716. After development of most of the code we began debugging our infrastructure. We used a few thousand devices randomly chosen for this purpose. We noticed at this time that one of the machines already had an unknown binary in the <font face="Courier, monospace">/tmp</font> directory that looked suspicious. A simple <font face="Courier, monospace">strings</font> command used on that binary revealed contents like <font face="Courier, monospace">synflood, ackflood,</font> etc., the usual abuse stuff one would find in malicious botnet binaries. We quickly discovered that this was a bot called Aidra, published only a few days before.
  1717.  
  1718. Aidra is a classic bot that needs an IRC C&amp;C server. With over 250 KB its binary is quite large and requires <font face="Courier, monospace">wget</font> on the target machines. Apparently its author only built it for a few platforms, so a majority of our target devices could not be infected with Aidra. Since Aidra was clearly made for malicious actions and we could actually see their Internet scale deployment at that moment, we decided to let our bot stop telnet after deployment and applied the same iptable rules Aidra does, if <font face="Courier, monospace">iptables</font> was available. This step was required to block Aidra from exploiting these machines for malicious activity. Since we did not change anything permanently, restarting the device undid these changes. We figured that the collateral damage as a result of this action would be far less than Aidra exploiting these devices.
  1719.  
  1720. Within one day our binary was deployed to around one hundred thousand devices - enough for our research purposes. We believe Aidra gained a litte more than half of that amount. The weeks after our initial deployment we were able to build binaries for a few more platforms. We also probed telnet every 24 hours on every IP address. Since many devices restart every few days and needed to be reinstalled again, over time we gained machines that Aidra lost. Aidra apparently installed itself permanently on a few devices like Dreambox and a few other Mips platforms. This most likely affects less than 30 thousand devices.
  1721.  
  1722. With our binary running on all major platforms, our botnet was available at a size of around 420 Thousand Clients.
  1723.  
  1724. <a href="http://internetcensus2012.bitbucket.org/images/clientmap_16to9_1600x900.jpg"><img style="width:600px" src="http://internetcensus2012.bitbucket.org/images/clientmap_16to9_small.jpg"></a>
  1725. Figure 1: Carna Botnet client distribution March to December 2012. ~420K Clients
  1726.  
  1727. <h2>5 Scanning Methods</h2>
  1728. <h3>5.1 ICMP Ping</h3>
  1729. A modified version of fping was used to send ICMP ping requests to every IP address. We did fast scans where we probed the IPv4 address space within a day, as well as a long term scan where the IP address space was probed for 6 weeks on a rate of approximately one scan of the complete IPv4 address space every few days. In total we have sent and stored 52 billion ICMP probes.
  1730. <h3>5.2 Reverse DNS</h3>
  1731. A modified version of libevents asynchronous reverse DNS sample code was used to request the DNS name for every IPv4 address. Most clients use their Internet provider's nameserver. The size and capacity of these nameservers may not be suitable for large scale DNS requests so we chose the biggest 16 DNS servers we discovered, e.g. Google, Level3, Verizon and some others. This job ran several times in 2012, resulting in 10.5 billion stored records.
  1732. <h3>5.3 Nmap</h3>
  1733. A number of the MIPS machines had enough RAM and computing power to run a downsized version of Nmap.
  1734.  
  1735. We used these machines to run sync scans of the top 100 ports and several scans on random ports to get sample data of all ports. These scans resulted in 2.8 billion records for ~660 million IPs with 71 billion ports tested.
  1736.  
  1737. Before doing a sync scan Nmap did hostprobes to determine if the host was alive. The Nmap hostprobe sends an ICMP echo request, a TCP SYN packet to port 443, a TCP ACK packet to port 80, and an ICMP timestamp request. This resulted in 19.5 billion stored hostprobe records.
  1738.  
  1739. For some reachable IP addresses Nmap was able to get an IP ID sequence and TCP/IP fingerprint. Since that was only possible on some IP addresses and not all of our deployed Nmap versions contained these abilities, this resulted in 75 million stored IP ID sequence records and 80 million stored TCP/IP fingerprints.
  1740. <h3>5.4 Service Probes</h3>
  1741. Nmap comes with a file called <font face="Courier New, monospace">nmap-service-probes</font>. This file contains probe data that is sent to ports as well as matching rules for the data that may be given in response. For details on how Nmap version detection works and the grammar of this file see <a href="http://nmap.org/book/vscan.html">nmap.org</a>.
  1742.  
  1743. We used the Nmap service probe file as a reference to build a binary that contained all 85 service probes Nmap provides. We used that binary to send these probes to every port proposed in the Nmap service probe file as well as a few missing ports that seemed interesting. 632 TCP and 110 UDP ports were probed on every IPv4 address, some ports were tested with multiple probes. To keep the size of the returned files smaller, and due to the fact that the vast majority of all probes timeout anyway, we reported back only every ~30th timed out or closed port. For the closed ports, this was later changed to report back every 5th closed port.
  1744.  
  1745. Over the course of three months in mid-2012 we sent approximately 4000 billion service probes, 175 billion of which where reported back and saved. On 15th and 16th of December we probed the top 30 ports so we would have a more up to date version on release. This provided approximately 5 billion additional saved service probes.
  1746.  
  1747. A detailed overview of what probes were sent to which ports is available <a href="http://internetcensus2012.bitbucket.org/serviceprobe_overview.html">here</a>
  1748. <h3>5.5 Traceroute</h3>
  1749. Approximately 70% of all open devices are either too small, don't run linux or only have a very limited telnet interface making it impossible to start or even upload a binary. Some of these machines provided a few diagnosis commands like ping, and interestingly traceroute on a limited shell.
  1750.  
  1751. We developed a modified version of our telnet scanner to find and log into theses devices. After login the connection was kept active and traceroute was called on the remote shell. The results were compressed by our binary and sent to the middle nodes. Since most IP ranges are empty, choosing random IPs as targets for these traceroutes would result in a very slow scanning speed, because it needed some time for the traceroute to timeout. So instead of choosing random targets the telnet scanner was used to determine target IPs. If the telnet scan got a response from the IP then the IP address was added to a queue for tracerouting.
  1752.  
  1753. This was started because it was a fun idea to let very small devices log into even smaller and less capable devices to use them for something. We kept this running only for a few days to prove that it works. The result is 68 million traceroute records.
  1754.  
  1755. <h2>6 Analysis</h2>
  1756. <h3>6.1 Hilbert Curves</h3>
  1757. To get a visual overview of ICMP records we converted the one-dimensional, 32-bit IP addresses into two dimensions using a <a href="http://en.wikipedia.org/wiki/Hilbert_curve">Hilbert Curve</a>, inspired by <a href="http://xkcd.com/195/">xkcd</a>. This curve keeps nearby addresses physically near each other and it is fractal, so we can zoom in or out to control detail. Figure 2 shows 420 Million IP addresses that responded to ICMP ping requests at least two times between June and October 2012. Address blocks are labeled based on IANA's list of IPv4 allocations that can be found <a href="http://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.xml">here</a>. Each pixel in the original 4096 x 4096 image represents a single /24 network containing up to 256 hosts. The pixel color shows the utilization of each /24 based on the number of probe responses. Black areas represent addresses that did not respond to the probes. Blue represents low utilization (at least one response), and red represents 100% utilization. This image was generated to be comparable to Figure 3, created 2006 by CAIDA in an Internet census project [<a href="http://www.isi.edu/ant/lander/">isi.edu</a>].
  1758.  
  1759. <div style="float:left;width:100%;padding-top:30px;padding-bottom:30px">
  1760. <div style="float:left;padding-right:20px">
  1761.  
  1762.  
  1763. <a class="link" href="http://internetcensus2012.bitbucket.org/images/hilbert_icmp_map_lowquality.jpg"> <img style="width:500px" src="http://internetcensus2012.bitbucket.org/images/2012_hilbert_icmp_map_small.jpg"></a>
  1764. Figure 2: 2012 IPv4 Census Map, Carna Botnet
  1765. </div>
  1766. <div style="float:left">
  1767. <img style="width:500px" src="http://internetcensus2012.bitbucket.org/images/2006_hilbert_icmp_map_small.jpg">
  1768. Figure 3: 2006 IPv4 Census Map, Source: <a class="link" href="http://www.caida.org/research/id-consumption/census-map/">caida.org</a>
  1769. </div>
  1770. </div>
  1771.  
  1772. We also modified the Hilbert browser, developed by ISI in their Internet mapping project [<a href="http://www.isi.edu/ant/address/">isi.edu</a>]. This browser shows ICMP ping records, as well as service probe and reverse DNS information. It allows zooming in and out into the IP space and an optional overlay allows highlighting of IP ranges. All images as well as the Hilbert browser use data from June to October 2012. There is more data available for download, but we concentrated the analysis on this time frame. Our version of this browser is available <a href="hilbert/index.html">here</a>. The sourcecode of this version as well as code to generate image tiles is part of the <a class="link" href="http://internetcensus2012.bitbucket.org/download/code.tar.bz2">code pack</a>.
  1773.  
  1774. We should mention that we are in no way associated to ISI or any researcher who worked at the ISI census project. We just took over the design for the Hilbert maps they made to have comparable images, as well as their Hilbert browser because it would have been a waste of time to code our own version.
  1775.  
  1776. <img style="width:600px" src="http://internetcensus2012.bitbucket.org/images/hilbert_interface.jpg">
  1777. Figure 4: Hilbert web browser
  1778.  
  1779. <h3>6.2 World Maps</h3>
  1780. To get a geographic overview we determined the geolocation of all IP addresses that respond to ICMP ping requests or have open ports. We used MaxMinds freely available GeoLite database [<a href="http://dev.maxmind.com/geoip/geolite">maxmind.com</a>] for geolocation mapping. Different versions of this image are available for download <a href="http://internetcensus2012.bitbucket.org/images.html">here</a>
  1781.  
  1782. <a href="http://internetcensus2012.bitbucket.org/images/worldmap_lowres_16to9_1600x900.png"> <img style="width:600px" src="http://internetcensus2012.bitbucket.org/images/worldmap_lowres_16to9_small.jpg"></a>
  1783. Figure 5: ~460 Million IP addresses on worldmap
  1784.  
  1785. To test if we could see a day night rhythm in the utilization of IP spaces we used all ICMP records to generate a series of images that show the difference from daily average utilization per half an hour. We composed theses images to a GIF animation that clearly shows a day night rhythm. The difference between day and night is lower for US and Central Europe because of the higher number of "always on" Internet connections. Full resolution GIFs and single images are available for download <a href="http://internetcensus2012.bitbucket.org/images.html">here</a>.
  1786. <div style="float:left;width:100%;padding-top:30px;padding-bottom:40px">
  1787. <div style="float:left;padding-right:20px">
  1788. <img id="gif1" style="width:600px" src="http://internetcensus2012.bitbucket.org/images/geovideo_frame_000_lowres.jpg">
  1789. <span class="link" onclick="document.getElementById(&quot;gif1&quot;).src=&quot;images/geovideo_lowres.gif&quot;">Click here </span> to start animation
  1790. </div>
  1791. <div style="float:left">
  1792. <div id="hilbertmap_youtube">
  1793. <img id="gif2" style="width:350px" src="http://internetcensus2012.bitbucket.org/images/hilbertvideo_frame_0000.jpg">
  1794. <span class="link" onclick="document.getElementById(&quot;gif2&quot;).src=&quot;images/hilbertvideo_lowres.gif&quot;">Click here </span> to start animation
  1795. </div>    
  1796. </div>
  1797. </div>
  1798. <h3>6.3 Reverse DNS</h3>
  1799. To get an overview of reverse DNS records we made a series of lists showing the top, most used names for the first four domain hierarchy levels. A few examples are shown below. Full lists are available <a href="http://internetcensus2012.bitbucket.org/tld_overview.html">here</a>.
  1800.  
  1801. <div style="float:left;width:100%;padding-top:30px;padding-bottom:30px">
  1802. <div style="float:left;width:200px;padding-right:30px">
  1803. <table id="sortable" style="width:200px">
  1804. <thead>
  1805. <tr><th>Count </th>
  1806. <th>TLD </th>
  1807. </tr></thead>
  1808. <tbody>
  1809. <tr><td>374670873</td><td>.net</td></tr>
  1810. <tr><td>199029228</td><td>.com</td></tr>
  1811. <tr><td>75612578</td><td>.jp</td></tr>
  1812. <tr><td>28059515</td><td>.it</td></tr>
  1813. <tr><td style="text-align:right"><a href="http://internetcensus2012.bitbucket.org/tld_overview.html">more..</a></td><td></td></tr>
  1814. </tbody>
  1815. </table>
  1816. </div>
  1817. <div style="float:left;width:200px;padding-right:30px">
  1818. <table id="sortable" style="width:200px">
  1819. <thead>
  1820. <tr><th>Count </th>
  1821. <th>Domain </th>
  1822. <th>TLD </th>
  1823. </tr></thead>
  1824. <tbody>
  1825. <tr><td>61327865</td><td>ne</td><td>jp</td></tr>
  1826. <tr><td>34434270</td><td>bbtec</td><td>net</td></tr>
  1827. <tr><td>30352347</td><td>comcast</td><td>net</td></tr>
  1828. <tr><td>27949325</td><td>myvzw</td><td>com</td></tr>
  1829. <tr><td>24919353</td><td>rr</td><td>com</td></tr>
  1830. <tr><td>22117491</td><td>sbcglobal</td><td>net</td></tr>
  1831. <tr><td></td><td><a href="http://internetcensus2012.bitbucket.org/domain_overview.html">more..</a></td></tr>
  1832. </tbody>
  1833. </table>
  1834. </div>
  1835. <div style="float:left;width:200px;">
  1836. <table id="sortable" style="width:200px">
  1837. <thead>
  1838. <tr><th>Count </th>
  1839. <th>Subdomain </th>
  1840. <th>Domain </th>
  1841. <th>TLD </th>
  1842. </tr></thead>
  1843. <tbody>
  1844. <tr><td>16492585</td><td>res</td><td>rr</td><td>com</td></tr>
  1845. <tr><td>16378226</td><td>static</td><td>ge</td><td>com</td></tr>
  1846. <tr><td>15550342</td><td>pools</td><td>spcsDNS</td><td>net</td></tr>
  1847. <tr><td>14902477</td><td>163data</td><td>com</td><td>cn</td></tr>
  1848. <tr><td></td><td><a href="http://internetcensus2012.bitbucket.org/subdomain_overview.html">more..</a></td></tr>
  1849. </tbody>
  1850. </table>
  1851. </div>
  1852. </div>
  1853. <h3>6.4 Service Probes</h3>
  1854. All records returned in response to service probes were matched against rules from Nmap's <font face="Courier, monospace">nmap-service-probes</font> file to determine service names and versions where possible. The quality of these matches depends on Nmap's matching rules. We added some more rules to catch several further services we noticed during debugging. For most services the matching is quite accurate. If a port had been probed multiple times we chose the most likely match based on how often that match had occurred and how much information it contained so that the lists only contained one match per port and per IP. Full matching results can be found as <a href="http://internetcensus2012.bitbucket.org/serviceprobe_overview.html">browsable lists</a> as well as tab separated raw lists in the <a href="http://internetcensus2012.bitbucket.org/download.html">downloads</a> section.
  1855. <div style="float:left;width:100%;padding-top:30px;">
  1856. <div style="float:left;width:500px;padding-right:30px;">
  1857. Port 80 Tcp, ~70.84 Million IP addresses
  1858. Allegro RomPager is the second most used webserver
  1859. <table id="nicetable" style="width:500px">
  1860. <thead>
  1861. <tr><th>Servicename </th>
  1862. <th>Product </th>
  1863. <th>Count </th>
  1864. <th>Percent </th>
  1865. </tr></thead>
  1866. <tbody>
  1867. <tr><td>http</td><td>Apache</td><td>14208112</td><td>20.057</td></tr>
  1868. <tr><td>http</td><td>Allegro RomPager</td><td>13116974</td><td>18.517</td></tr>
  1869. <tr><td>http</td><td></td><td>8881082</td><td>12.537</td></tr>
  1870. <tr><td>http</td><td>Microsoft IIS httpd</td><td>6071267</td><td>8.571</td></tr>
  1871. <tr><td>http</td><td>AkamaiGHost</td><td>4064402</td><td>5.738</td></tr>
  1872. <tr><td>http</td><td>nginx</td><td>4045993</td><td>5.712</td></tr>
  1873. <tr><td>http</td><td>micro_httpd</td><td>1991840</td><td>2.812</td></tr>
  1874. <tr><td></td><td><a href="http://internetcensus2012.bitbucket.org/serviceprobes/80_TCP_product.html">..more</a></td><td></td><td></td></tr>
  1875. </tbody>
  1876. </table>
  1877. </div>
  1878. <div style="float:left;width:500px;">
  1879.  
  1880. Port 9100 Tcp, ~244 Thousand IP addresses
  1881.  
  1882. ~200 Thousand identifiable printers
  1883. <table id="nicetable" style="width:500px">
  1884. <thead>
  1885. <tr><th>Servicename </th>
  1886. <th>Product </th>
  1887. <th>Count </th>
  1888. <th>Percent </th>
  1889. </tr></thead>
  1890. <tbody>
  1891. <tr><td>no match</td><td>-/-</td><td>29994</td><td>12.264</td></tr>
  1892. <tr><td>hp-pjl</td><td>HP LaserJet P2055 Series</td><td>6628</td><td>2.71</td></tr>
  1893. <tr><td>hp-pjl</td><td>hp LaserJet 4250</td><td>4678</td><td>1.913</td></tr>
  1894. <tr><td>irc</td><td>Dancer ircd</td><td>4095</td><td>1.674</td></tr>
  1895. <tr><td>hp-pjl</td><td>LASERJET 4050</td><td>3554</td><td>1.453</td></tr>
  1896. <tr><td>telnet</td><td>Cisco router telnetd</td><td>3497</td><td>1.43</td></tr>
  1897. <tr><td>hp-pjl</td><td>HP LaserJet P2015 Series</td><td>3237</td><td>1.324</td></tr>
  1898. <tr><td></td><td><a href="http://internetcensus2012.bitbucket.org/serviceprobes/9100_TCP_product.html">..more</a></td><td></td><td></td></tr>
  1899. </tbody>
  1900. </table>
  1901. </div>
  1902. </div>
  1903. <div style="float:left;width:100%;padding-top:30px;padding-bottom:30px">
  1904. <div style="float:left;width:500px;">
  1905.  
  1906. Port 49152 Tcp, ~4.11  Million IP addresses
  1907.  
  1908. ~2.4 Million devices <a class="link" href="https://community.rapid7.com/docs/DOC-2150">Portable SDK for UPnP devices</a>
  1909. <table id="nicetable" style="width:500px">
  1910. <thead>
  1911. <tr><th>Servicename </th>
  1912. <th>Product </th>
  1913. <th>Count </th>
  1914. <th>Percent </th>
  1915. </tr></thead>
  1916. <tbody>
  1917. <tr><td>upnp</td><td>Portable SDK for UPnP devices</td><td>2405517</td><td>58.479</td></tr>
  1918. <tr><td>upnp</td><td>Intel UPnP reference SDK</td><td>1268457</td><td>30.836</td></tr>
  1919. <tr><td>http</td><td></td><td>237412</td><td>5.772</td></tr>
  1920. <tr><td>http</td><td>Linux</td><td>101333</td><td>2.463</td></tr>
  1921. <tr><td>http</td><td>Apple ODS DVD/CD Sharing Agent httpd</td><td>36321</td><td>0.883</td></tr>
  1922. <tr><td>http</td><td>Apache</td><td>12737</td><td>0.31</td></tr>
  1923. <tr><td>rtsp</td><td>Apple AirTunes rtspd</td><td>9856</td><td>0.24</td></tr>
  1924.  
  1925. <tr><td></td><td><a href="http://internetcensus2012.bitbucket.org/serviceprobes/49152_TCP_product.html">..more</a></td><td></td><td></td></tr>
  1926. </tbody>
  1927. </table>
  1928. </div>
  1929.  
  1930. </div>
  1931. <h3>6.5 Numbers</h3>
  1932.  
  1933. The numbers below were filtered to eliminate noise and match a timeperiod from June 2012 to October 2012.
  1934. The data used for these numbers is the same that was used for the <a href="hilbert/index.html">browsable Hilbert map</a>.
  1935.  
  1936. <p style="line-height: 120%">
  1937. </p><ul>
  1938. <li>420 Million IPs responded to ICMP ping requests more than once. [<a class="link" href="hilbert/index.html?kind=ICMP%20echo">Map</a>]</li>
  1939. <li>165 Million IPs had one or more of the top 150 ports open. 36 Million of these IPs did not respond to ICMP ping. [<a class="link" href="hilbert/index.html?kind=Port%20open">Map</a>]</li>
  1940. <li>141 Million IPs had only closed/reset ports and did not respond to ICMP ping. Most of these were firewalled IP ranges where it was uncertain if they had actual computers behind them. [<a class="link" href="hilbert/index.html?kind=Port%20reset/closed">Map</a>]</li>
  1941. <li>1051 Million IPs had a reverse DNS record. [<a class="link" href="hilbert/index.html?kind=Reverse%20DNS">Map</a>] 729 Million of these IPs had nothing more and did not respond to any probe.</li>
  1942. <li>30000 /16 networks contained IPs that responded to ICMP ping, 14000 /16 networks contained 90% of all pingable IPs.</li>
  1943. <li>4.3 Million /24 networks contained all 420 Million pingable IPs.</li>
  1944. </ul>
  1945.  
  1946. <i>So, how big is the Internet?</i>
  1947.  
  1948. That depends on how you count. 420 Million pingable IPs + 36 Million more that had one or more ports open, making 450 Million that were definitely in use and reachable from the rest of the Internet. 141 Million IPs were firewalled, so they could count as "in use". Together this would be 591 Million used IPs. 729 Million more IPs just had reverse DNS records. If you added those, it would make for a total of 1.3 Billion used IP addresses. The other 2.3 Billion addresses showed no sign of usage.
  1949.  
  1950.  
  1951. <h3>6.6 Noise</h3>
  1952.  
  1953. While analyzing the data we had gathered we noticed some noise. IP ranges that should have been empty, seemed to show a very low level of usage. A closer look revealed that some of our scanning machines seem to have been behind enforced proxies or provider firewalls. They rerouted some of the probes to different IPs, leading to false responses. This noise could be filtered out quite easily because it was mostly present on very common services that had been probed several times. For the service probes, the most noisy ports are 80, 443 and 8080. This seems to result from enforced provider proxies. Port 53 also contains noise because providers redirect this port to their own nameservers. Port 25 contains some noise because of provider firewalls, probably to prevent spam. The noise on port 80 and 443 also affects Nmap's hostprobes because it uses these ports to determine if a host is alive. Because of the large number of different probes we recorded for each IP address, this noise can be filtered out almost completely.
  1954.  
  1955. <h2>7 Conclusion</h2>
  1956. This was a fun project and there are many more things we could have done, but this concludes our work. The binary stops itself after some time and most of the deployed versions have already done that by now. All of our initial goals as well as some extras like traceroute were achieved, we have completed, to our knowledge, the largest and most comprehensive IPv4 census ever. With a growing number of IPv6 hosts on the Internet, 2012 may have been the last time a census like this was possible.
  1957.  
  1958. We hope other researchers will find the data we have collected useful and that this publication will help raise some awareness that, while everybody is talking about high class exploits and cyberwar, four simple stupid default telnet passwords can give you access to hundreds of thousands of consumer as well as tens of thousands of industrial devices all over the world.
  1959.  
  1960. <h2>8 Trivia</h2>
  1961. Since it seems to be somewhat of a tradition to name bots after Roman or Greek divinities we chose "Carna" as the name for our bot. Carna was the roman goddess for the protection of inner organs and health and was later confused with the goddess of doorsteps and hinges. This name seems like a good choice for a bot that runs mostly on embedded routers.
  1962.  
  1963. If you are watching port scans that run at rates from 3 to 5 billion IPs per hour for weeks, the Internet shrinks and seems small and empty. If you try to analyze, visualize, sort and compress the collected data, it quickly gets annoyingly gigantic again.
  1964.  
  1965. A lot of devices and services we have seen during our research should never be connected to the public Internet at all.
  1966. As a rule of thumb, if you believe that "nobody would connect that to the Internet, really nobody", there are at least 1000 people who did. Whenever you think "that shouldn't be on the Internet but will probably be found a few times" it's there a few hundred thousand times. Like half a million printers, or a Million Webcams, or devices that have root as a root password.
  1967.  
  1968. We would also like to mention that building and running a gigantic botnet and then watching it as it scans nothing less than the whole Internet at rates of billions of IPs per hour over and over again is really as much fun as it sounds like.
  1969. <h2>9 Who and Why</h2>
  1970. You may ask yourself who we are and why we did what we did.
  1971.  
  1972. In reality, we is me. I chose we as a form for this documentation because its nicer to read, and mentioning myself a thousand times just sounded egotistical.
  1973.  
  1974. The why is also simple: I did not want to ask myself for the rest of my life how much fun it could have been or if the infrastructure I imagined in my head would have worked as expected. I saw the chance to really work on an Internet scale, command hundred thousands of devices with a click of my mouse, portscan and map the whole Internet in a way nobody had done before, basically have fun with computers and the Internet in a way very few people ever will. I decided it would be worth my time.
  1975.  
  1976. Just in case someone else tries to take credit for my work: My <a href="http://internetcensus2012.bitbucket.org/download/InternetCensus2012.asc"> PGP public key</a>
  1977.  
  1978. </div>
  1979. <p><a rel="nofollow" href="https://www.askapache.com/hacking/internet-census-2012-port-scanning-using-insecure-embedded-devices-carna-botnet/">Internet Census 2012 &#8211; Port scanning using insecure embedded devices &#8211; Carna Botnet</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  1980. ]]></content:encoded>
  1981. <wfw:commentRss>https://www.askapache.com/hacking/internet-census-2012-port-scanning-using-insecure-embedded-devices-carna-botnet/feed/</wfw:commentRss>
  1982. <slash:comments>0</slash:comments>
  1983. </item>
  1984. <item>
  1985. <title>OpenSearch description document</title>
  1986. <link>https://www.askapache.com/seo/opensearch-description-document/</link>
  1987. <comments>https://www.askapache.com/seo/opensearch-description-document/#respond</comments>
  1988. <pubDate>Fri, 22 Jul 2016 05:36:09 +0000</pubDate>
  1989. <dc:creator><![CDATA[AskApache]]></dc:creator>
  1990. <category><![CDATA[SEO]]></category>
  1991.  
  1992. <guid isPermaLink="false">https://www.askapache.com/?p=8440</guid>
  1993. <description><![CDATA[<p><a rel="nofollow" href="https://www.askapache.com/seo/opensearch-description-document/">OpenSearch description document</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  1994. ]]></description>
  1995. <content:encoded><![CDATA[http://www.opensearch.org/Specifications/OpenSearch/1.1
  1996.  
  1997. <p>This document defines the OpenSearch description document, the OpenSearch Query element, the OpenSearch URL template syntax, and the OpenSearch response elements.  Collectively these formats may be referred to as "OpenSearch 1.1" or simply "OpenSearch".
  1998. </p><p><i>Search clients can use OpenSearch description documents to learn about the public interface of a search engine.  These description documents contain parameterized URL templates that indicate how the search client should make search requests.  Search engines can use the OpenSearch response elements to add search metadata to results in a variety of content formats.</i>
  1999. </p>
  2000. <a name="Namespace"></a><h2> <span class="mw-headline"> Namespace </span></h2>
  2001. <p>The XML Namespaces URI for the XML data formats described in this specification is:
  2002. </p>
  2003. <dl><dd> <code>http://a9.com/-/spec/opensearch/1.1/</code>
  2004. </dd></dl>
  2005. <a name="OpenSearch_description_document"></a><h2> <span class="mw-headline"> OpenSearch description document </span></h2>
  2006. <a name="Overview_2"></a><h3> <span class="mw-headline"> Overview </span></h3>
  2007. <p>An OpenSearch description document can be used to describe the web interface of a search engine.
  2008. </p>
  2009. <a name="Examples"></a><h3> <span class="mw-headline"> Examples </span></h3>
  2010. <p><i>Example of a simple OpenSearch description document:</i>
  2011. </p>
  2012. <pre> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  2013. &lt;OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"&gt;
  2014.   &lt;ShortName&gt;Web Search&lt;/ShortName&gt;
  2015.   &lt;Description&gt;Use Example.com to search the Web.&lt;/Description&gt;
  2016.   &lt;Tags&gt;example web&lt;/Tags&gt;
  2017.   &lt;Contact&gt;[email protected]&lt;/Contact&gt;
  2018.   &lt;Url type="application/rss+xml"
  2019.        template="http://example.com/?q={searchTerms}&amp;amp;pw={startPage?}&amp;amp;format=rss"/&gt;
  2020. &lt;/OpenSearchDescription&gt;
  2021. </pre>
  2022. <p><i>Example of a detailed OpenSearch description document:</i>
  2023. </p>
  2024. <pre> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  2025. &lt;OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"&gt;
  2026.   &lt;ShortName&gt;Web Search&lt;/ShortName&gt;
  2027.   &lt;Description&gt;Use Example.com to search the Web.&lt;/Description&gt;
  2028.   &lt;Tags&gt;example web&lt;/Tags&gt;
  2029.   &lt;Contact&gt;[email protected]&lt;/Contact&gt;
  2030.   &lt;Url type="application/atom+xml"
  2031.        template="http://example.com/?q={searchTerms}&amp;amp;pw={startPage?}&amp;amp;format=atom"/&gt;
  2032.   &lt;Url type="application/rss+xml"
  2033.        template="http://example.com/?q={searchTerms}&amp;amp;pw={startPage?}&amp;amp;format=rss"/&gt;
  2034.   &lt;Url type="text/html"
  2035.        template="http://example.com/?q={searchTerms}&amp;amp;pw={startPage?}"/&gt;
  2036.   &lt;LongName&gt;Example.com Web Search&lt;/LongName&gt;
  2037.   &lt;Image height="64" width="64" type="image/png"&gt;http://example.com/websearch.png&lt;/Image&gt;
  2038.   &lt;Image height="16" width="16" type="image/vnd.microsoft.icon"&gt;http://example.com/websearch.ico&lt;/Image&gt;
  2039.   &lt;Query role="example" searchTerms="cat" /&gt;
  2040.   &lt;Developer&gt;Example.com Development Team&lt;/Developer&gt;
  2041.   &lt;Attribution&gt;
  2042.     Search data Copyright 2005, Example.com, Inc., All Rights Reserved
  2043.   &lt;/Attribution&gt;
  2044.   &lt;SyndicationRight&gt;open&lt;/SyndicationRight&gt;
  2045.   &lt;AdultContent&gt;false&lt;/AdultContent&gt;
  2046.   &lt;Language&gt;en-us&lt;/Language&gt;
  2047.   &lt;OutputEncoding&gt;UTF-8&lt;/OutputEncoding&gt;
  2048.   &lt;InputEncoding&gt;UTF-8&lt;/InputEncoding&gt;
  2049. &lt;/OpenSearchDescription&gt;
  2050. </pre>
  2051. <a name="Type"></a><h3> <span class="mw-headline"> Type </span></h3>
  2052. <p>OpenSearch description documents are referred to via the following type:
  2053. </p>
  2054. <dl><dd> <code>application/opensearchdescription+xml</code>
  2055. </dd></dl>
  2056. <p><i>This type is pending IANA registration.</i>
  2057. </p>
  2058. <a name="Extensibility"></a><h3> <span class="mw-headline"> Extensibility </span></h3>
  2059. <p>OpenSearch description documents can be extended with foreign markup provided that all foreign elements and attributes are associated with an explicit XML namespace distinct from that of the core OpenSearch format.  When possible, the foreign XML namespace URI should resolve to a document that indicates the intention and format of the extension.  Clients that encounter unrecognized foreign markup should continue to process the document as if the markup did not appear.
  2060. </p>
  2061. <a name="OpenSearch_description_elements"></a><h3> <span class="mw-headline"> OpenSearch description elements </span></h3>
  2062. <a name="The_.22OpenSearchDescription.22_element"></a><h4> <span class="mw-headline"> The "OpenSearchDescription" element </span></h4>
  2063. <p>The root node of the OpenSearch description document.
  2064. </p>
  2065. <dl><dd> Parent: None
  2066. </dd><dd> Requirements: The element <b>must</b> appear exactly once as the root node of the document.
  2067. </dd></dl>
  2068. <p><i>Example:</i>
  2069. </p>
  2070. <pre> &lt;OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"&gt;
  2071.    &lt;!--- ... ---&gt;
  2072. &lt;/OpenSearchDescription&gt;
  2073. </pre>
  2074. <a name="The_.22ShortName.22_element"></a><h4> <span class="mw-headline"> The "ShortName" element </span></h4>
  2075. <p>Contains a brief human-readable title that identifies this search engine.
  2076. </p>
  2077. <dl><dd> Parent: OpenSearchDescription
  2078. </dd><dd> Restrictions: The value must contain 16 or fewer characters of plain text.  The value must not contain HTML or other markup.
  2079. </dd><dd> Requirements: This element <b>must</b> appear exactly once.
  2080. </dd></dl>
  2081. <p><i>Example:</i>
  2082. </p>
  2083. <pre> &lt;ShortName&gt;Web Search&lt;/ShortName&gt;
  2084. </pre>
  2085. <a name="The_.22Description.22_element"></a><h4> <span class="mw-headline"> The "Description" element </span></h4>
  2086. <p>Contains a human-readable text description of the search engine.
  2087. </p>
  2088. <dl><dd> Parent: OpenSearchDescription
  2089. </dd><dd> Restrictions: The value must contain 1024 or fewer characters of plain text.  The value must not contain HTML or other markup.
  2090. </dd><dd> Requirements: This element <b>must</b> appear exactly once.
  2091. </dd></dl>
  2092. <p><i>Example:</i>
  2093. </p>
  2094. <pre> &lt;Description&gt;Use Example.com to search the Web.&lt;/Description&gt;
  2095. </pre>
  2096. <a name="The_.22Url.22_element"></a><h4> <span class="mw-headline"> The "Url" element </span></h4>
  2097. <p>Describes an interface by which a client can make requests for an external resource, such as search results, search suggestions, or additional description documents.
  2098. </p>
  2099. <dl><dd> Parent: OpenSearchDescription
  2100. </dd><dd> Attributes:
  2101. <dl><dd> <code>template</code> - The URL template to be processed according to the <a href="#OpenSearch_URL_template_syntax" title="">OpenSearch URL template syntax</a>.
  2102. <dl><dd> Requirements: This attribute is <b>required</b>.
  2103. </dd></dl>
  2104. </dd><dd> <code>type</code> - The MIME type of the resource being described.
  2105. <dl><dd> Restrictions: The value must be a valid MIME type.
  2106. </dd><dd> Requirements: This attribute is <b>required</b>.
  2107. </dd></dl>
  2108. </dd><dd> <code>rel</code> - The role of the resource being described in relation to the description document.
  2109. <dl><dd> Restrictions:  Contains a space-delimited list of valid rel value tokens.  See the <a href="#Url_rel_values" title="">Url rel values</a> specification for allowed rel values.
  2110. </dd><dd> Default: "results"
  2111. </dd><dd> Requirements: This attribute is optional.
  2112. </dd></dl>
  2113. </dd><dd> <code>indexOffset</code> - The index number of the first search result.
  2114. <dl><dd> Restrictions: The value must be an integer.
  2115. </dd><dd> Default: "1"
  2116. </dd><dd> Requirements: This attribute is optional.
  2117. </dd></dl>
  2118. </dd><dd> <code>pageOffset</code> - The page number of the first set of search results.
  2119. <dl><dd> Restrictions: The value must be an integer.
  2120. </dd><dd> Default: "1"
  2121. </dd><dd> Requirements: This attribute is optional.
  2122. </dd></dl>
  2123. </dd></dl>
  2124. </dd><dd> Requirements: This element <b>must</b> appear one or more times.
  2125. </dd></dl>
  2126. <p><i>Example of a Url element describing a request for a HTML search results page:</i>
  2127. </p>
  2128. <pre> &lt;Url type="text/html"
  2129.      template="http://example.com/search?q={searchTerms}&amp;amp;pw={startPage?}" /&gt;
  2130. </pre>
  2131. <p><i>Example of a Url element describing a request for search results over RSS, starting with element index 0:</i>
  2132. </p>
  2133. <pre> &lt;Url type="application/rss+xml"
  2134.      indexOffset="0"
  2135.      rel="results"
  2136.      template="http://example.com/?q={searchTerms}&amp;amp;start={startIndex?}&amp;amp;format=rss" /&gt;
  2137. </pre>
  2138. <p><i>Example of a Url element describing a request for search suggestions over JSON:</i>
  2139. </p>
  2140. <pre> &lt;Url type="application/json"
  2141.      rel="suggestions"
  2142.      template="http://example.com/suggest?q={searchTerms}" /&gt;
  2143. </pre>
  2144. <p><br>
  2145. <i>Example of a Url element describing a request to refresh the OpenSearch description document itself:</i>
  2146. </p>
  2147. <pre> &lt;Url type="application/opensearchdescription+xml"
  2148.      rel="self"
  2149.      template="http://example.com/osd.xml" /&gt;
  2150. </pre>
  2151. <a name="Url_rel_values"></a><h5> <span class="mw-headline"> Url rel values </span></h5>
  2152. <p>Rel attribute strings can contain a space-delimited list of one or more semantically meaningful rel value tokens.  An empty rel attribute value should be treated by the client as if the rel attribute was not present at all.
  2153. </p><p>If a client does not recognize the semantic meaning of any rel value token, then the containing Url should be ignored by the client.
  2154. </p><p>Rel value tokens may be either fully qualified tokens (e.g., "http://example.com/rel#foo") or unqualified tokens (e.g., "results").
  2155. </p><p>All fully qualified tokens must be a <a href="http://www.ietf.org/rfc/rfc1738.txt" class="external text" title="http://www.ietf.org/rfc/rfc1738.txt" rel="nofollow">valid URL</a>.  The semantic meaning of any fully qualified token is outside the scope of this specification, but convention dictates that the URL should resolve to a resource that describes the relationship.
  2156. </p><p>All unqualified tokens must be a lowercase alphanumeric string of the form [a-z][a-z\-]+.  Only those tokens listed below have meaning defined in this specification.
  2157. </p><p>Rel values:
  2158. </p>
  2159. <dl><dd> <code>"results"</code> (default)
  2160. <dl><dd>   Represents a request for search results in the specified format.
  2161. </dd></dl>
  2162. </dd><dd> <code>"suggestions"</code>
  2163. <dl><dd>   Represents a request for search suggestions in the specified format.  See the <a href="/Specifications/OpenSearch/Extensions/Suggestions" title="Specifications/OpenSearch/Extensions/Suggestions">OpenSearch Suggestions extension</a> for further details.
  2164. </dd></dl>
  2165. </dd><dd> <code>"self"</code>
  2166. <dl><dd>   Represents the canonical URL of this description document.
  2167. </dd></dl>
  2168. </dd><dd> <code>"collection"</code>
  2169. <dl><dd>   Represents a request for a set of resources.
  2170. </dd></dl>
  2171. </dd></dl>
  2172. <a name="The_.22Contact.22_element"></a><h4> <span class="mw-headline"> The "Contact" element </span></h4>
  2173. <p>Contains an email address at which the maintainer of the description document can be reached.
  2174. </p>
  2175. <dl><dd> Parent: OpenSearchDescription
  2176. </dd><dd> Restrictions: The value must conform to the requirements of Section 3.4.1 "Addr-spec specification" in <a href="http://tools.ietf.org/html/rfc2822" class="external" title="http://tools.ietf.org/html/rfc2822">RFC 2822</a>.
  2177. </dd><dd> Requirements: This element may appear zero or one time.
  2178. </dd></dl>
  2179. <p><i>Example:</i>
  2180. </p>
  2181. <pre> &lt;Contact&gt;[email protected]&lt;/Contact&gt;
  2182. </pre>
  2183. <a name="The_.22Tags.22_element"></a><h4> <span class="mw-headline"> The "Tags" element </span></h4>
  2184. <p>Contains a set of words that are used as keywords to identify and categorize this search content.  Tags must be a single word and are delimited by the space character (' ').  
  2185. </p>
  2186. <dl><dd> Parent: OpenSearchDescription
  2187. </dd><dd> Restrictions: The value must contain 256 or fewer characters of plain text.   The value must not contain HTML or other markup.
  2188. </dd><dd> Requirements: This element may appear zero or one time.  
  2189. </dd></dl>
  2190. <p><i>Example:</i>
  2191. </p>
  2192. <pre> &lt;Tags&gt;example web&lt;/Tags&gt;
  2193. </pre>
  2194. <a name="The_.22LongName.22_element"></a><h4> <span class="mw-headline"> The "LongName" element </span></h4>
  2195. <p>Contains an extended human-readable title that identifies this search engine.
  2196. </p><p><i>Search clients should use the value of the ShortName element if this element is not available.</i>
  2197. </p>
  2198. <dl><dd> Parent: OpenSearchDescription
  2199. </dd><dd> Restrictions: The value must contain 48 or fewer characters of plain text.   The value must not contain HTML or other markup.
  2200. </dd><dd> Requirements: This element may appear zero or one time.
  2201. </dd></dl>
  2202. <p><i>Example:</i>
  2203. </p>
  2204. <pre> &lt;LongName&gt;Example.com Web Search&lt;/LongName&gt;
  2205. </pre>
  2206. <a name="The_.22Image.22_element"></a><h4> <span class="mw-headline"> The "Image" element </span></h4>
  2207. <p>Contains a URL that identifies the location of an image that can be used in association with this search content.
  2208. </p><p><i>Image sizes are offered as a hint to the search client.  The search client will choose the most appropriate image for the available space and should give preference to those listed first in the OpenSearch description document.  Square aspect ratios are recommended.  When possible, search engines should offer a 16x16 image of type "image/x-icon" or "image/vnd.microsoft.icon" (the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn_icons.asp" class="external text" title="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn_icons.asp" rel="nofollow">Microsoft ICON format</a>) and a 64x64 image of type "image/jpeg" or "image/png".</i>
  2209. </p>
  2210. <dl><dd> Parent: OpenSearchDescription
  2211. </dd><dd> Attributes:
  2212. <dl><dd> <code>height</code> – Contains the height, in pixels, of this image.
  2213. <dl><dd> Restrictions: The value must be a non-negative integer.
  2214. </dd><dd> Requirements: This attribute is optional.
  2215. </dd></dl>
  2216. </dd><dd> <code>width</code> – Contains the width, in pixels, of this image.
  2217. <dl><dd> Restrictions: The value must be a non-negative integer.
  2218. </dd><dd> Requirements: This attribute is optional.
  2219. </dd></dl>
  2220. </dd><dd> <code>type</code> – Contains the the MIME type of this image.
  2221. <dl><dd> Restrictions: The value must be a valid MIME type.
  2222. </dd><dd> Requirements: This attribute is optional.
  2223. </dd></dl>
  2224. </dd></dl>
  2225. </dd><dd> Restrictions: The value must be a URI.
  2226. </dd><dd> Requirements: This element may appear zero, one, or more times.
  2227. </dd></dl>
  2228. <p><i>Example:</i>
  2229. </p>
  2230. <pre> &lt;Image height="16" width="16" type="image/x-icon"&gt;http://example.com/favicon.ico&lt;/Image&gt;
  2231. &lt;Image height="64" width="64" type="image/png"&gt;http://example.com/websearch.png&lt;/Image&gt;
  2232. </pre>
  2233. <a name="The_.22Query.22_element"></a><h4> <span class="mw-headline"> The "Query" element </span></h4>
  2234. <p>Defines a search query that can be performed by search clients.   Please see the <a href="#OpenSearch_Query_element" title="">OpenSearch Query element</a> specification for more information.
  2235. </p><p><i>OpenSearch description documents should include at least one Query element of role="example" that is expected to return search results.  Search clients may use this example query to validate that the search engine is working properly.</i>
  2236. </p>
  2237. <dl><dd> Parent: OpenSearchDescription
  2238. </dd><dd> Requirements: This element may appear zero or more times.
  2239. </dd></dl>
  2240. <p><i>Example:</i>
  2241. </p>
  2242. <pre> &lt;Query role="example" searchTerms="cat" /&gt;
  2243. </pre>
  2244. <a name="The_.22Developer.22_element"></a><h4> <span class="mw-headline"> The "Developer" element </span></h4>
  2245. <p>Contains the human-readable name or identifier of the creator or maintainer of the description document.
  2246. </p><p><i>The developer is the person or entity that created the description document, and may or may not be the owner, author, or copyright holder of the source of the content itself.</i>
  2247. </p>
  2248. <dl><dd> Parent: OpenSearchDescription
  2249. </dd><dd> Restrictions: The value must contain 64 or fewer characters of plain text.  The value must not contain HTML or other markup.
  2250. </dd><dd> Requirements: This element may appear zero or one time.
  2251. </dd></dl>
  2252. <p><i>Example:</i>
  2253. </p>
  2254. <pre> &lt;Developer&gt;Example.com Development Team&lt;/Developer&gt;
  2255. </pre>
  2256. <a name="The_.22Attribution.22_element"></a><h4> <span class="mw-headline"> The "Attribution" element </span></h4>
  2257. <p>Contains a list of all sources or entities that should be credited for the content contained in the search feed.
  2258. </p>
  2259. <dl><dd> Parent: OpenSearchDescription
  2260. </dd><dd> Restrictions: The value must contain 256 or fewer characters of plain text.   The value must not contain HTML or other markup.
  2261. </dd><dd> Requirements: This element may appear zero or one time.
  2262. </dd></dl>
  2263. <p><i>Example:</i>
  2264. </p>
  2265. <pre> &lt;Attribution&gt;Search data copyright Example.com, Inc.&lt;/Attribution&gt;
  2266. </pre>
  2267. <a name="The_.22SyndicationRight.22_element"></a><h4> <span class="mw-headline"> The "SyndicationRight" element </span></h4>
  2268. <p>Contains a value that indicates the degree to which the search results provided by this search engine can be queried, displayed, and redistributed.
  2269. </p>
  2270. <dl><dd> Parent: OpenSearchDescription
  2271. </dd><dd> Values: The value must be one of the following strings (case insensitive):
  2272. <dl><dd> <code>"open"</code> –
  2273. <dl><dd> The search client may request search results.
  2274. </dd><dd> The search client may display the search results to end users.
  2275. </dd><dd> The search client may send the search results to other search clients.
  2276. </dd></dl>
  2277. </dd><dd> <code>"limited"</code> –
  2278. <dl><dd> The search client may request search results.
  2279. </dd><dd> The search client may display the search results to end users.
  2280. </dd><dd> The search client may not send the search results to other search clients.  
  2281. </dd></dl>
  2282. </dd><dd> <code>"private"</code> –
  2283. <dl><dd> The search client may request search results.
  2284. </dd><dd> The search client may not display the search results to end users.
  2285. </dd><dd> The search client may not send the search results to other search clients.  
  2286. </dd></dl>
  2287. </dd><dd> <code>"closed"</code> -
  2288. <dl><dd> The search client may not request search results.
  2289. </dd></dl>
  2290. </dd></dl>
  2291. </dd><dd> Default: "open"
  2292. </dd><dd> Requirements: This element may appear zero or one time.
  2293. </dd></dl>
  2294. <p><i>Example:</i>
  2295. </p>
  2296. <pre> &lt;SyndicationRight&gt;open&lt;/SyndicationRight&gt;
  2297. </pre>
  2298. <a name="The_.22AdultContent.22_element"></a><h4> <span class="mw-headline"> The "AdultContent" element </span></h4>
  2299. <p>Contains a boolean value that should be set to true if the search results may contain material intended only for adults.
  2300. </p><p><i>As there are no universally applicable guidelines as to what constitutes "adult" content, the search engine should make a good faith effort to indicate when there is a possibility that search results may contain material inappropriate for all audiences.</i>
  2301. </p>
  2302. <dl><dd> Parent: OpenSearchDescription
  2303. </dd><dd> Values:
  2304. <dl><dd> The values "false", "FALSE", "0", "no", and "NO" will be considered boolean FALSE; all other strings will be considered boolean TRUE.
  2305. </dd></dl>
  2306. </dd><dd> Default: "false"
  2307. </dd><dd> Requirements: This element may appear zero or one time.
  2308. </dd></dl>
  2309. <p><i>Example:</i>
  2310. </p>
  2311. <pre> &lt;AdultContent&gt;false&lt;/AdultContent&gt;
  2312. </pre>
  2313. <a name="The_.22Language.22_element"></a><h4> <span class="mw-headline"> The "Language" element </span></h4>
  2314. <p>Contains a string that indicates that the search engine supports search results in the specified language.
  2315. </p><p><i>An <a href="#OpenSearch_description_document" title="">OpenSearch description document</a> should include one <a href="#The_.22Language.22_element" title="">"Language" element</a> for each language that the search engine supports.  If the search engine also supports queries for any arbitrary language then the OpenSearch description document should include a Language element with a value of "*".   The <a href="#The_.22language.22_parameter" title="">"language" template parameter</a> in the <a href="#OpenSearch_URL_template" title="">OpenSearch URL template</a> can be used to allow the search client to choose among the available languages.</i>
  2316. </p>
  2317. <dl><dd> Parent: OpenSearchDescription
  2318. </dd><dd> Restrictions: The value must conform to the <a href="http://www.w3.org/TR/2004/REC-xml-20040204/#sec-lang-tag" class="external text" title="http://www.w3.org/TR/2004/REC-xml-20040204/#sec-lang-tag" rel="nofollow">XML 1.0 Language Identification</a>, as specified by <a href="http://tools.ietf.org/html/rfc5646" class="external" title="http://tools.ietf.org/html/rfc5646">RFC 5646</a>.  In addition, the value of "*" will signify that the search engine does not restrict search results to any particular language.
  2319. </dd><dd> Default: "*".
  2320. </dd><dd> Requirements: This element may appear zero, one, or more times.
  2321. </dd></dl>
  2322. <p><i>Example:</i>
  2323. </p>
  2324. <pre> &lt;Language&gt;en-us&lt;/Language&gt;
  2325. &lt;Language&gt;*&lt;/Language&gt;
  2326. </pre>
  2327. <a name="The_.22InputEncoding.22_element"></a><h4> <span class="mw-headline"> The "InputEncoding" element </span></h4>
  2328. <p>Contains a string that indicates that the search engine supports search requests encoded with the specified character encoding.
  2329. </p><p><i>An <a href="#OpenSearch_description_document" title="">OpenSearch description document</a> should include one <a href="#The_.22InputEncoding.22_element" title="">"InputEncoding" element</a> for each character encoding that can be used to encode search requests.   The <a href="#The_.22inputEncoding.22_parameter" title="">"inputEncoding" template parameter</a> in the <a href="#OpenSearch_URL_template" title="">OpenSearch URL template</a> can be used to require the search client to identify which encoding is being used to encode the current search request.</i>
  2330. </p>
  2331. <dl><dd> Parent: OpenSearchDescription
  2332. </dd><dd> Restrictions: The value must conform to the <a href="http://www.w3.org/TR/2004/REC-xml-20040204/#charencoding" class="external text" title="http://www.w3.org/TR/2004/REC-xml-20040204/#charencoding" rel="nofollow">XML 1.0 Character Encodings</a>, as specified by the <a href="http://www.iana.org/assignments/character-sets" class="external text" title="http://www.iana.org/assignments/character-sets" rel="nofollow">IANA Character Set Assignments</a>.
  2333. </dd><dd> Default: "UTF-8".
  2334. </dd><dd> Requirements: This element may appear zero, one, or more times.
  2335. </dd></dl>
  2336. <p><i>Example:</i>
  2337. </p>
  2338. <pre> &lt;InputEncoding&gt;UTF-8&lt;/InputEncoding&gt;
  2339. </pre>
  2340. <a name="The_.22OutputEncoding.22_element"></a><h4> <span class="mw-headline"> The "OutputEncoding" element </span></h4>
  2341. <p>Contains a string that indicates that the search engine supports search responses encoded with the specified character encoding.
  2342. </p><p><i>An <a href="#OpenSearch_description_document" title="">OpenSearch description document</a> should include one <a href="#The_.22OutputEncoding.22_element" title="">"OutputEncoding" element</a> for each character encoding that can be used to encode search responses.   The <a href="#The_.22outputEncoding.22_parameter" title="">"outputEncoding" template parameter</a> in the <a href="#OpenSearch_URL_template" title="">OpenSearch URL template</a> can be used to allow the search client to choose a character encoding in the search response.</i>
  2343. </p>
  2344. <dl><dd> Parent: OpenSearchDescription
  2345. </dd><dd> Restrictions: The value must conform to the <a href="http://www.w3.org/TR/2004/REC-xml-20040204/#charencoding" class="external text" title="http://www.w3.org/TR/2004/REC-xml-20040204/#charencoding" rel="nofollow">XML 1.0 Character Encodings</a>, as specified by the <a href="http://www.iana.org/assignments/character-sets" class="external text" title="http://www.iana.org/assignments/character-sets" rel="nofollow">IANA Character Set Assignments</a>.
  2346. </dd><dd> Default: "UTF-8".
  2347. </dd><dd> Requirements: This element may appear zero, one, or more times.
  2348. </dd></dl>
  2349. <p><i>Example:</i>
  2350. </p>
  2351. <pre> &lt;OutputEncoding&gt;UTF-8&lt;/OutputEncoding&gt;
  2352. </pre>
  2353. <a name="Autodiscovery"></a><h3> <span class="mw-headline"> Autodiscovery </span></h3>
  2354. <p><i>Search engines that publish OpenSearch description documents can assist search clients in the discovery of OpenSearch interfaces through the use of "link" elements.  Search engines that support OpenSearch should include a reference to the related OpenSearch description document on each page of search results.</i>
  2355. </p>
  2356. <a name="Autodiscovery_in_RSS.2FAtom"></a><h4> <span class="mw-headline"> Autodiscovery in RSS/Atom </span></h4>
  2357. <p>RSS and Atom documents may reference related <a href="#OpenSearch_description_document" title="">OpenSearch description documents</a> via the Atom 1.0 "link" element, as specified in Section 4.2.7 of <a href="http://tools.ietf.org/html/rfc4287" class="external" title="http://tools.ietf.org/html/rfc4287">RFC 4287</a>.
  2358. </p><p><i>The "rel" attribute of the link element should contain the value "search" when referring to OpenSearch description documents.  This relationship value is pending IANA registration.  The reuse of the Atom link element is recommended in the context of other syndication formats that do natively support comparable functionality.</i>
  2359. </p><p>The following restrictions apply:
  2360. </p>
  2361. <ul><li> The "type" attribute must contain the value "application/opensearchdescription+xml".
  2362. </li><li> The "rel" attribute must contain the value "search".  
  2363. </li><li> The "href" attribute must contain a URI that resolves to an OpenSearch description document.
  2364. </li><li> The "title" attribute may contain a human-readable plain text string describing the search engine.
  2365. </li></ul>
  2366. <p><i>Example of Atom-based search results that include an OpenSearch autodiscovery link element:</i>
  2367. </p>
  2368. <pre> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  2369. &lt;feed xmlns="http://www.w3.org/2005/Atom"
  2370.       xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"&gt;
  2371.   &lt;!-- ... ---&gt;
  2372.   &lt;link rel="search"
  2373.         href="http://example.com/opensearchdescription.xml"
  2374.         type="application/opensearchdescription+xml"
  2375.         title="Content Search" /&gt;
  2376.   &lt;!-- ... ---&gt;
  2377. &lt;/feed&gt;
  2378. </pre>
  2379. <p><br>
  2380. <i>Example of RSS-based search results that include an OpenSearch autodiscovery link element:</i>
  2381. </p>
  2382. <pre> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  2383. &lt;rss version="2.0"
  2384.      xmlns:atom="http://www.w3.org/2005/Atom"&gt;
  2385.   &lt;channel&gt;
  2386.     &lt;!--- ... ---&gt;
  2387.     &lt;atom:link rel="search"
  2388.                href="http://example.com/opensearchdescription.xml"
  2389.                type="application/opensearchdescription+xml"
  2390.                title="Content Search" /&gt;
  2391.     &lt;!--- ... ---&gt;
  2392.   &lt;/channel&gt;
  2393. &lt;/rss&gt;
  2394. </pre>
  2395. <a name="Autodiscovery_in_HTML.2FXHTML"></a><h4> <span class="mw-headline"> Autodiscovery in HTML/XHTML </span></h4>
  2396. <p>HTML and XHTML documents may reference related <a href="#OpenSearch_description_document" title="">OpenSearch description documents</a> via the <a href="http://www.w3.org/TR/REC-html40/struct/links.html#h-12.3" class="external text" title="http://www.w3.org/TR/REC-html40/struct/links.html#h-12.3" rel="nofollow">HTML 4.0 &lt;link/&gt; element</a>.
  2397. </p><p>The following restrictions apply:
  2398. </p>
  2399. <ul><li> The "type" attribute must contain the value "application/opensearchdescription+xml".
  2400. </li><li> The "rel" attribute must contain the value "search".  
  2401. </li><li> The "href" attribute must contain a URI that resolves to an OpenSearch description document.
  2402. </li><li> The "title" attribute may contain a human-readable plain text string describing the search engine.
  2403. </li><li> The HTML &lt;head/&gt; element should include a "profile" attribute that contains the value "http://a9.com/-/spec/opensearch/1.1/".
  2404. </li></ul>
  2405. <p><i>Example of an HTML document that includes OpenSearch autodiscovery link elements:</i>
  2406. </p>
  2407. <pre> &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
  2408. &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"&gt;
  2409.   &lt;head profile="http://a9.com/-/spec/opensearch/1.1/"&gt;
  2410.     &lt;!--- ... ---&gt;
  2411.     &lt;link rel="search"
  2412.           type="application/opensearchdescription+xml"
  2413.           href="http://example.com/content-search.xml"
  2414.           title="Content search" /&gt;
  2415.     &lt;link rel="search"
  2416.           type="application/opensearchdescription+xml"
  2417.           href="http://example.com/comment-search.xml"
  2418.           title="Comments search" /&gt;
  2419.     &lt;!--- ... ---&gt;
  2420.   &lt;/head&gt;
  2421.   &lt;body&gt;
  2422.     &lt;!--- ... ---&gt;
  2423.   &lt;/body&gt;
  2424. &lt;/html&gt;
  2425. </pre>
  2426. <a name="MIME_type_application.2Fopensearchdescription.2Bxml"></a><h4> <span class="mw-headline"> MIME type application/opensearchdescription+xml </span></h4>
  2427. <p>For the purposes of <a href="http://tools.ietf.org/html/rfc4288" class="external" title="http://tools.ietf.org/html/rfc4288">RFC 4288</a> section 4.10 this specification contains the registration template for MIME type <code>application/opensearchdescription+xml</code>. <i>This type is pending IANA registration.</i>
  2428. </p>
  2429. <div style="width: 40em"><pre style='font-size: smaller' width='78'>   Type name:      application
  2430.  
  2431.   Subtype name:   opensearchdescription+xml
  2432.  
  2433.   Required parameters:
  2434.                   There are no required parameters.
  2435.  
  2436.   Optional parameters:
  2437.                   charset (defaults to "UTF-8")
  2438.  
  2439.   Encoding considerations:
  2440.                   Identical to those of "application/xml" as described
  2441.                   in RFC 3023; especially "UTF-8" (RFC 3629) and its
  2442.                   proper subset "US-ASCII" are supposed to work.
  2443.  
  2444.                   For non-ASCII documents served as "text/xml" the
  2445.                   "charset" parameter is required; this might be
  2446.                   relevant when authors are unable to configure the
  2447.                   server hosting their OSD (OpenSearch Description
  2448.                   document).
  2449.  
  2450.   Security considerations:
  2451.                   All general security and privacy considerations for
  2452.                   sending queries to servers specified in an URL are
  2453.                   applicable.  
  2454.  
  2455.                   Where clients support the optional update feature in
  2456.                   OSDs it affects the privacy of users.
  2457.  
  2458.                   The Ecmascript API AddSearchProvider() typically
  2459.                   enforces a "same origin" policy for the OSD; the URL
  2460.                   element within the OSD can designate a third party
  2461.                   as search provider.
  2462.  
  2463.                   An OSD can claim to be a search description for X,
  2464.                   but actually do something else.
  2465.  
  2466.   Interoperability considerations:
  2467.                   OSDs use the &lt;http://a9.com/-/spec/opensearch/1.1/&gt;
  2468.                   XML name space, optionally in conjunction with other
  2469.                   XML name spaces for extensions or application specific
  2470.                   purposes.
  2471.  
  2472.   Published specification:
  2473.                   &lt;http://www.opensearch.org/Specifications/OpenSearch/1.1&gt;
  2474.  
  2475.   Applications that use this media type:
  2476.                   Various Web browsers, search engines, and software
  2477.                   libraries support OSDs.  The "search" link relation
  2478.                   is used on many Web pages with this media type.
  2479.      
  2480.                   The Ecmascript API AddSearchProvider() documented for
  2481.                   WhatWG HTML uses this media type.
  2482.   Additional information:
  2483.                   OSDs have no "magic numbers" as defined in RFC 4288.
  2484.                   There are no special "common file name extensions" for
  2485.                   OSDs, OSDs are XML documents.  If specific extensions
  2486.                   are desired the conventional ".osdx" or ".a9.xml" might
  2487.                   do the trick.
  2488.  
  2489.   Person &amp; email address to contact for further information:
  2490.                   &lt;http://groups.google.com/group/opensearch&gt;
  2491.                   &lt;http://www.opensearch.org/Community/Guidelines&gt;
  2492.  
  2493.   Intended usage: COMMON
  2494.  
  2495.   Restrictions on usage:
  2496.                   None
  2497.  
  2498.   Author:         DeWitt Clinton
  2499.  
  2500.   Change controller:
  2501.                   &lt;http://www.opensearch.org/&gt;
  2502. </pre></div>
  2503. <a name="OpenSearch_URL_template_syntax"></a><h2> <span class="mw-headline"> OpenSearch URL template syntax </span></h2>
  2504. <a name="Overview_3"></a><h3> <span class="mw-headline"> Overview </span></h3>
  2505. <p>The OpenSearch URL template format can be used to represent a parameterized form of the URL by which a search engine is queried.
  2506. </p><p><i>The search client will process the URL template and attempt to replace each instance of a template parameter, generally represented in the form <code>{name}</code>, with a value determined at query time.</i>
  2507. </p><p><i>By default, parameter names are considered part of the OpenSearch 1.1 template namespace, and definitions for a set of core search parameter names are provided in this specification.  However, search engines and search clients can adopt new parameter names using an extensibility mechanism based on the XML namespace prefix conventions.</i>
  2508. </p>
  2509. <a name="Examples_2"></a><h3> <span class="mw-headline"> Examples </span></h3>
  2510. <p><i>Example of a search URL template that contains a template parameter:</i>
  2511. </p>
  2512. <pre> http://example.com/search?q={searchTerms}
  2513. </pre>
  2514. <p><i>Example of a search URL template that contains an optional template parameter:</i>
  2515. </p>
  2516. <pre> http://example.com/feed/{startPage?}
  2517. </pre>
  2518. <p><i>Example of a search URL template that contains an optional template parameter in an extended namespace, shown in the context of a <a href="#The_.22Url.22_element" title="">Url element</a>:</i>
  2519. </p>
  2520. <pre> &lt;Url type="application/rss+xml"
  2521.      xmlns:example="http://example.com/opensearchextensions/1.0/"
  2522.      template="http://example.com?q={searchTerms}&amp;amp;c={example:color?}"/&gt;
  2523. </pre>
  2524. <a name="Context"></a><h3> <span class="mw-headline"> Context </span></h3>
  2525. <p>This specification refers to the use of the OpenSearch URL template syntax specifically within the context of the <a href="#The_.22Url.22_element" title="">"Url" element</a> in an <a href="#OpenSearch_description_document" title="">OpenSearch description document</a>.
  2526. </p>
  2527. <a name="Template_grammar"></a><h3> <span class="mw-headline"> Template grammar </span></h3>
  2528. <p>The grammar of an OpenSearch URL template is defined by the following set of ABNF rules, as specified in <a href="http://tools.ietf.org/html/rfc2234" class="external" title="http://tools.ietf.org/html/rfc2234">RFC 2234</a>.
  2529. </p><p>The grammar rules defined in this document build upon a subset of the rules defined for the Uniform Resource Identifier (URI): Generic Syntax in <a href="http://tools.ietf.org/html/rfc3986" class="external" title="http://tools.ietf.org/html/rfc3986">RFC 3986</a>.  For brevity, rules already stated in <a href="http://tools.ietf.org/html/rfc3986" class="external" title="http://tools.ietf.org/html/rfc3986">RFC 3986</a> are referenced in this document by rule name alone and are not restated here in their entirety.
  2530. </p>
  2531. <pre class="prettyprint lang-config"> ttemplate      = tscheme ":" thier-part [ "?" tquery ] [ "#" tfragment ]
  2532. tscheme        = *( scheme / tparameter )
  2533. thier-part     = "//" tauthority ( tpath-abempty / tpath-absolute / tpath-rootless / path-empty )
  2534. tauthority     = [ tuserinfo "@" ] thost [ ":" tport ]
  2535. tuserinfo      = *( userinfo / tparameter )
  2536. thost          = *( host / tparameter )
  2537. tport          = *( port / tparameter )
  2538. tpath-abempty  = *( "/" tsegment )
  2539. tsegment       = *( segment / tparameter )
  2540. tpath-absolute = "/" [ tsegment-nz *( "/" tsegment ) ]
  2541. tsegment-nz    = *( segment-nz / tparameter )
  2542. tpath-rootless = tsegment-nz *( "/" tsegment )
  2543. tparameter     = "{" tqname [ tmodifier ] "}"
  2544. tqname         = [ tprefix ":" ] tlname
  2545. tprefix        = *pchar
  2546. tlname         = *pchar
  2547. tmodifier      = "?"
  2548. tquery         = *( query / tparameter )
  2549. tfragement     = *( fragement / tparameter )
  2550. </pre>
  2551. <a name="Substitution_rules"></a><h3> <span class="mw-headline"> Substitution rules </span></h3>
  2552. <p>The search client <b>must</b> replace every instance of a template parameter with a value before the search request is performed.
  2553. </p><p><i>If a search engine wishes to indicate that a template parameter is optional and can be replaced with the empty string, then the "?" notation described in the section on <a href="#Optional_template_parameters" title="">optional template parameters</a> should be used.</i>
  2554. </p>
  2555. <a name="Parameter_names"></a><h4> <span class="mw-headline"> Parameter names </span></h4>
  2556. <p>A parameter name consists of an optional parameter name prefix followed by the local parameter name.  If the parameter name prefix is present then it will be separated from the local parameter name with the ":" character.  All parameter names are associated with a parameter namespace.  In the case of unqualified parameter names, the local parameter name is implicitly associated with the OpenSearch 1.1 namespace.  In the case of fully qualified parameter names, the local parameter name is explicitly associated with an external namespace via the parameter name prefix.
  2557. </p>
  2558. <a name="Case_sensitivity_of_parameter_names"></a><h4> <span class="mw-headline"> Case sensitivity of parameter names </span></h4>
  2559. <p>Both the parameter name prefix and the local parameter name are case sensitive.
  2560. </p>
  2561. <a name="Parameter_name_prefix"></a><h4> <span class="mw-headline"> Parameter name prefix </span></h4>
  2562. <p>A parameter name prefix associates a local parameter name with a parameter namespace.  All parameter name prefixes must be previously declared as an <a href="http://www.w3.org/TR/REC-xml-names/" class="external text" title="http://www.w3.org/TR/REC-xml-names/" rel="nofollow">XML namespace</a> prefix on the containing element or ancestor elements.
  2563. </p><p><i>The choice of prefix is at the discretion of the author of the OpenSearch description document.  Search clients should make no assumption as to the meaning of any particular literal prefix string, and should rely exclusively on the mapping of prefix strings to XML namespace declarations when parsing fully qualified parameter names.</i>
  2564. </p><p><i>Example of two equivalent URL templates that will be processed identically by search clients:</i>
  2565. </p>
  2566. <pre> &lt;Url type="application/rss+xml"
  2567.      xmlns:a="http://example.com/extensions/"
  2568.      template="http://example.com?q={a:localname?}"/&gt;
  2569. &lt;Url type="application/rss+xml"
  2570.      xmlns:b="http://example.com/extensions/"
  2571.      template="http://example.com?q={b:localname?}"/&gt;
  2572. </pre>
  2573. <a name="Unqualified_parameter_names"></a><h4> <span class="mw-headline"> Unqualified parameter names </span></h4>
  2574. <p>Unqualified parameter names consist of only a local parameter name and do not include a parameter name prefix.  Unqualified parameter names in OpenSearch URL templates are implicitly associated with the <a href="#Namespace" title="">OpenSearch 1.1 namespace</a>.
  2575. </p><p><i>This specification includes an exhaustive list of all unqualified <a href="#OpenSearch_1.1_parameters" title="">OpenSearch 1.1 parameter names</a>.</i>
  2576. </p><p><i>Example of an unqualified parameter name:</i>
  2577. </p>
  2578. <pre> &lt;Url type="application/rss+xml"
  2579.      template="http://example.com/?q={searchTerms}"/&gt;
  2580. </pre>
  2581. <a name="Fully_qualified_parameter_names"></a><h4> <span class="mw-headline"> Fully qualified parameter names </span></h4>
  2582. <p>Fully qualified parameter names consist of a parameter name prefix, followed by the ":" character, followed by the local parameter name.  Fully qualified parameter names are associated with the namespace identified by the paramater name prefix, as it appears as an XML namespace declaration on the containing element or ancestor elements.
  2583. </p><p><i>Example of a fully qualified parameter name:</i>
  2584. </p>
  2585. <pre> &lt;Url type="application/rss+xml"
  2586.      xmlns:example="http://example.com/opensearchextensions/1.0/"
  2587.      template="http://example.com?f={example:format?}"/&gt;
  2588. </pre>
  2589. <a name="Required_template_parameters"></a><h4> <span class="mw-headline"> Required template parameters </span></h4>
  2590. <p>Required template parameters are template parameters that do not contain a template parameter modifier.  The search client may use the default value if one is known, but may not use the empty string as a value.
  2591. </p><p><i>Example of a required template parameter:</i>
  2592. </p>
  2593. <pre> {searchTerms}
  2594. </pre>
  2595. <a name="Optional_template_parameters"></a><h4> <span class="mw-headline"> Optional template parameters </span></h4>
  2596. <p>Optional template parameters are template parameters that contain a template parameter modifier equal to "?".  The search client may use the empty string as a value if no other value is available.
  2597. </p><p><i>Example of an optional template parameter:</i>
  2598. </p>
  2599. <pre> {startPage?}
  2600. </pre>
  2601. <a name="OpenSearch_1.1_parameters"></a><h3> <span class="mw-headline"> OpenSearch 1.1 parameters </span></h3>
  2602. <p>The following local parameter names are identified with the OpenSearch 1.1 namespace.  The list is exhaustive; only the local parameter names listed below may appear unqualified in an OpenSearch URL template.
  2603. </p><p>Search clients should be prepared to substitute reasonable values for these parameter names when they appear in an OpenSearch URL template.
  2604. </p>
  2605. <a name="The_.22searchTerms.22_parameter"></a><h4> <span class="mw-headline"> The "searchTerms" parameter </span></h4>
  2606. <p>Replaced with the keyword or keywords desired by the search client.
  2607. </p>
  2608. <dl><dd> Restrictions: The value must be URL-encoded.
  2609. </dd></dl>
  2610. <a name="The_.22count.22_parameter"></a><h4> <span class="mw-headline"> The "count" parameter </span></h4>
  2611. <p>Replaced with the number of search results per page desired by the search client.
  2612. </p><p><i>Search clients should anticipate that the value of the "count" parameter may not be honored by the search engine, and should rely exclusively on the contents of <a href="#The_.22itemsPerPage.22_element" title="">the "itemsPerPage" response element</a> in calculating actual page size.</i>
  2613. </p>
  2614. <dl><dd> Restrictions:  The value must be a non-negative integer.
  2615. </dd></dl>
  2616. <a name="The_.22startIndex.22_parameter"></a><h4> <span class="mw-headline"> The "startIndex" parameter </span></h4>
  2617. <p>Replaced with the index of the first search result desired by the search client.
  2618. </p>
  2619. <dl><dd> Restrictions:  The value must be an integer.
  2620. </dd><dd> Default:  The value specified by the "indexOffset" attribute of the containing <a href="#The_.22Url.22_element" title="">Url element</a>.
  2621. </dd></dl>
  2622. <a name="The_.22startPage.22_parameter"></a><h4> <span class="mw-headline"> The "startPage" parameter </span></h4>
  2623. <p>Replaced with the page number of the set of search results desired by the search client.
  2624. </p>
  2625. <dl><dd> Restrictions: The value must be an integer.
  2626. </dd><dd> Default: The value specified by the "pageOffset" attribute of the containing <a href="#The_.22Url.22_element" title="">Url element</a>.
  2627. </dd></dl>
  2628. <a name="The_.22language.22_parameter"></a><h4> <span class="mw-headline"> The "language" parameter </span></h4>
  2629. <p>Replaced with a string that indicates that the search client desires search results in the specified language.
  2630. </p><p><i>An <a href="#OpenSearch_description_document" title="">OpenSearch description document</a> should include one <a href="#The_.22Language.22_element" title="">"Language" element</a> for each language that the search engine supports.  If the search engine also supports queries for any arbitrary language then the OpenSearch description document should include a Language element with a value of "*".   The <a href="#The_.22language.22_parameter" title="">"language" template parameter</a> in the <a href="#OpenSearch_URL_template" title="">OpenSearch URL template</a> can be used to allow the search client to choose among the available languages.</i>
  2631. </p>
  2632. <dl><dd> Restrictions: The value must conform to the <a href="http://www.w3.org/TR/2004/REC-xml-20040204/#sec-lang-tag" class="external text" title="http://www.w3.org/TR/2004/REC-xml-20040204/#sec-lang-tag" rel="nofollow">XML 1.0 Language Identification</a>, as specified by <a href="http://tools.ietf.org/html/rfc5646" class="external" title="http://tools.ietf.org/html/rfc5646">RFC 5646</a>.  In addition, a value of "*" will signify that the search client desires search results in any language.
  2633. </dd><dd> Default: "*"
  2634. </dd></dl>
  2635. <a name="The_.22inputEncoding.22_parameter"></a><h4> <span class="mw-headline"> The "inputEncoding" parameter </span></h4>
  2636. <p>Replaced with a string that indicates that the search client is performing the search request encoded with the specified character encoding.
  2637. </p><p><i>An <a href="#OpenSearch_description_document" title="">OpenSearch description document</a> should include one <a href="#The_.22InputEncoding.22_element" title="">"InputEncoding" element</a> for each character encoding that can be used to encode search requests.   The <a href="#The_.22inputEncoding.22_parameter" title="">"inputEncoding" template parameter</a> in the <a href="#OpenSearch_URL_template" title="">OpenSearch URL template</a> can be used to require the search client to identify which encoding is being used to encode the current search request.</i>
  2638. </p>
  2639. <dl><dd> Restrictions: The value must conform to the <a href="http://www.w3.org/TR/2004/REC-xml-20040204/#charencoding" class="external text" title="http://www.w3.org/TR/2004/REC-xml-20040204/#charencoding" rel="nofollow">XML 1.0 Character Encodings</a>, as specified by the <a href="http://www.iana.org/assignments/character-sets" class="external text" title="http://www.iana.org/assignments/character-sets" rel="nofollow">IANA Character Set Assignments</a>.
  2640. </dd><dd> Default: "UTF-8"
  2641. </dd></dl>
  2642. <a name="The_.22outputEncoding.22_parameter"></a><h4> <span class="mw-headline"> The "outputEncoding" parameter </span></h4>
  2643. <p>Replaced with a string that indicates that the search client desires a search response encoding with the specified character encoding.
  2644. </p><p><i>An <a href="#OpenSearch_description_document" title="">OpenSearch description document</a> should include one <a href="#The_.22OutputEncoding.22_element" title="">"OutputEncoding" element</a> for each character encoding that can be used to encode search responses.   The <a href="#The_.22outputEncoding.22_parameter" title="">"outputEncoding" template parameter</a> in the <a href="#OpenSearch_URL_template" title="">OpenSearch URL template</a> can be used to allow the search client to choose a character encoding in the search response.</i>
  2645. </p>
  2646. <dl><dd> Restrictions: The value must conform to the <a href="http://www.w3.org/TR/2004/REC-xml-20040204/#charencoding" class="external text" title="http://www.w3.org/TR/2004/REC-xml-20040204/#charencoding" rel="nofollow">XML 1.0 Character Encodings</a>, as specified by the <a href="http://www.iana.org/assignments/character-sets" class="external text" title="http://www.iana.org/assignments/character-sets" rel="nofollow">IANA Character Set Assignments</a>.
  2647. </dd><dd> Default: "UTF-8"
  2648. </dd></dl>
  2649. <a name="OpenSearch_Query_element"></a><h2> <span class="mw-headline"> OpenSearch Query element </span></h2>
  2650. <a name="Overview_4"></a><h3> <span class="mw-headline"> Overview </span></h3>
  2651. <p>The OpenSearch Query element can be used to define a specific search request that can be performed by a search client.
  2652. </p><p><i>The Query element attributes correspond to the search parameters in a URL template.  The core set of search parameters are explicitly defined as Query attributes, and custom parameters can be added via namespaces as needed.</i>
  2653. </p><p><i>Authors should provide at least one Query element of role="example" in each OpenSearch description document so that search clients can test the search engine.  Search engines should include a Query element of role="request" in each search response so that search clients can recreate the current search.</i>
  2654. </p>
  2655. <a name="Examples_3"></a><h3> <span class="mw-headline"> Examples </span></h3>
  2656. <p><i>Example of a Query element used in an OpenSearch description document to provide an example search request for search clients:</i>
  2657. </p>
  2658. <pre> &lt;Query role="example" searchTerms="cat" /&gt;
  2659. </pre>
  2660. <p><i>Example of a Query element used in an OpenSearch response to echo back the original search request:</i>
  2661. </p>
  2662. <pre> &lt;Query role="request" searchTerms="cat" startPage="1" /&gt;
  2663. </pre>
  2664. <p><i>Example of a Query element used in an OpenSearch response to correct the spelling of "OpenSurch":</i>
  2665. </p>
  2666. <pre> &lt;Query role="correction" searchTerms="OpenSearch" totalResults="854000" title="Spelling correction" /&gt;
  2667. </pre>
  2668. <p><i>Example of a Query element using an extended parameter:</i>
  2669. </p>
  2670. <pre> &lt;Query xmlns:custom="http://example.com/opensearchextensions/1.0/"
  2671.        role="example"
  2672.        searchTerms="cat"
  2673.        custom:color="blue"
  2674.        title="Sample search" /&gt;
  2675. </pre>
  2676. <p><i>Example of a Query element using a extended role:</i>
  2677. </p>
  2678. <pre> &lt;Query xmlns:custom="http://example.com/opensearchextensions/1.0/"
  2679.        role="custom:synonym"
  2680.        title="Synonym of &#039;cat&#039;"
  2681.        searchTerms="feline" /&gt;
  2682. </pre>
  2683. <p><i>Detailed example of a set of Query elements used in the context of an Atom-based OpenSearch response:</i>
  2684. </p>
  2685. <pre class="prettyprint lang-config"> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  2686. &lt;feed xmlns="http://www.w3.org/2005/Atom"
  2687.       xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"&gt;
  2688.   &lt;!--- ... ---&gt;
  2689.   &lt;opensearch:Query role="request" searchTerms="General Motors annual report" /&gt;
  2690.   &lt;opensearch:Query role="related" searchTerms="GM" title="General Motors stock symbol" /&gt;
  2691.   &lt;opensearch:Query role="related" searchTerms="automotive industry revenue" /&gt;
  2692.   &lt;opensearch:Query role="subset" searchTerms="General Motors annual report 2005"
  2693.   &lt;opensearch:Query role="superset" searchTerms="General Motors" /&gt;
  2694.   &lt;!-- ... --&gt;
  2695. &lt;/feed&gt;
  2696. </pre>
  2697. <a name="The_.22Query.22_element_2"></a><h3> <span class="mw-headline"> The "Query" element </span></h3>
  2698. <p>Describes a specific search request that can be made by the search client.
  2699. </p>
  2700. <dl><dd> Attributes:
  2701. <dl><dd> <code>role</code> - Contains a string identifying how the search client should interpret the search request defined by this Query element.
  2702. <dl><dd> Restrictions: See the <a href="#Role_values" title="">role values</a> specification for allowed role values.
  2703. </dd><dd> Requirements: This attribute is <b>required</b>.  
  2704. </dd></dl>
  2705. </dd><dd> <code>title</code> - Contains a human-readable plain text string describing the search request.
  2706. <dl><dd> Restrictions: The value must contain 256 or fewer characters of plain text.  The value must not contain HTML or other markup.
  2707. </dd><dd> Requirements: This attribute is optional.
  2708. </dd></dl>
  2709. </dd><dd> <code>totalResults</code> - Contains the expected number of results to be found if the search request were made.
  2710. <dl><dd> Restrictions: The value is a non-negative integer.
  2711. </dd><dd> Requirements: This attribute is optional.
  2712. </dd></dl>
  2713. </dd><dd> <code>searchTerms</code> - Contains the value representing the "searchTerms" as an <a href="#OpenSearch_1.1_parameters" title="">OpenSearch 1.1 parameter</a>.
  2714. <dl><dd> Restrictions: See the <a href="#The_.22searchTerms.22_parameter" title="">"searchTerms" parameter</a>.
  2715. </dd><dd> Requirements: This attribute is optional.
  2716. </dd></dl>
  2717. </dd><dd> <code>count</code> - Contains the value representing the "count" as a <a href="#OpenSearch_1.1_parameters" title="">OpenSearch 1.1 parameter</a>.
  2718. <dl><dd> Restrictions: See the <a href="#The_.22count.22_parameter" title="">"count" parameter</a>.
  2719. </dd><dd> Requirements: This attribute is optional.
  2720. </dd></dl>
  2721. </dd><dd> <code>startIndex</code> - Contains the value representing the "startIndex" as an <a href="#OpenSearch_1.1_parameters" title="">OpenSearch 1.1 parameter</a>.
  2722. <dl><dd> Restrictions: See the <a href="#The_.22startIndex.22_parameter" title="">"startIndex" parameter</a>.
  2723. </dd><dd> Requirements: This attribute is optional.
  2724. </dd></dl>
  2725. </dd><dd> <code>startPage</code> - Contains the value representing the "startPage" as an <a href="#OpenSearch_1.1_parameters" title="">OpenSearch 1.1 parameter</a>.
  2726. <dl><dd> Restrictions: See the <a href="#The_.22startPage.22_parameter" title="">"startPage" parameter</a>.
  2727. </dd><dd> Requirements: This attribute is optional.
  2728. </dd></dl>
  2729. </dd><dd> <code>language</code> - Contains the value representing the "language" as an <a href="#OpenSearch_1.1_parameters" title="">OpenSearch 1.1 parameter</a>.
  2730. <dl><dd> Restrictions: See the <a href="#The_.22language.22_parameter" title="">"language" parameter</a>.
  2731. </dd><dd> Requirements: This attribute is optional.
  2732. </dd></dl>
  2733. </dd><dd> <code>inputEncoding</code> - Contains the value representing the "inputEncoding" as an <a href="#OpenSearch_1.1_parameters" title="">OpenSearch 1.1 parameter</a>.
  2734. <dl><dd> Restrictions: See the <a href="#The_.22inputEncoding.22_parameter" title="">"inputEncoding" parameter</a>.
  2735. </dd><dd> Requirements: This attribute is optional.
  2736. </dd></dl>
  2737. </dd><dd> <code>outputEncoding</code> - Contains the value representing the "outputEncoding" as an <a href="#OpenSearch_1.1_parameters" title="">OpenSearch 1.1 parameter</a>.
  2738. <dl><dd> Restrictions: See the <a href="#The_.22outputEncoding.22_parameter" title="">"outputEncoding" parameter</a>.
  2739. </dd><dd> Requirements: This attribute is optional.
  2740. </dd></dl>
  2741. </dd></dl>
  2742. </dd></dl>
  2743. <p><i>Example:</i>
  2744. </p>
  2745. <pre> &lt;Query role="example" searchTerms="cat" /&gt;
  2746. </pre>
  2747. <a name="Query_element_extensibility"></a><h3> <span class="mw-headline"> Query element extensibility </span></h3>
  2748. <p>The Query element may contain additional attributes if the extended attributes are associated with a namespace.  Search clients should interpret extended attributes to represent the corresponding template parameter by the same name in the specified namespace.
  2749. </p><p><i>Example of a Query element representing a search request that contains an extended attribute that corresponds to an extended search parameter:</i>
  2750. </p>
  2751. <pre>&lt;OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
  2752.                       xmlns:custom="http://example.com/opensearchextensions/1.0/"&gt;
  2753.  &lt;Url type="text/html"
  2754.       template="http://example.com/search?color={custom:color?}" /&gt;
  2755.  &lt;Query role="example"  custom:color="blue" /&gt;
  2756.  &lt;!-- ... --&gt;
  2757. &lt;/OpenSearchDescription&gt;
  2758. </pre>
  2759. <a name="Role_values"></a><h3> <span class="mw-headline"> Role values </span></h3>
  2760. <p>A role value consists of an optional prefix followed by the local role value.  If the prefix is present it will be separated from the local role value with the ":" character.  All role values are associated with a namespace, either implicitly in the case of local role values, or explicitly via a prefix in the case of fully qualified role values.
  2761. </p>
  2762. <a name="Role_extensibility"></a><h4> <span class="mw-headline"> Role extensibility </span></h4>
  2763. <p>The role attribute may take on values beyond those specified in this document provided they are fully qualified with a prefix and associated with a declared namespace.  Clients that encounter unrecognized role values should continue to process the document as if the Query element containing the unrecognized role value did not appear.
  2764. </p>
  2765. <a name="Role_prefix"></a><h4> <span class="mw-headline"> Role prefix </span></h4>
  2766. <p>A role prefix associates a local role name with a namespace. All prefixes must be previously declared as an XML namespace prefix on the containing Query element or ancestor elements.
  2767. </p>
  2768. <a name="Local_role_values"></a><h4> <span class="mw-headline"> Local role values </span></h4>
  2769. <p>Local role values are not preceded by a prefix. Local role values are associated with the <a href="#Namespace" title="">OpenSearch 1.1 namespace</a>.
  2770. </p><p>The following role values are identified with the OpenSearch 1.1 namespace.  The list is exhaustive; only the role values listed below may appear in the OpenSearch 1.1 namespace.
  2771. </p><p>Role values:
  2772. </p>
  2773. <dl><dd> <code>"request"</code>
  2774. <dl><dd>   Represents the search query that can be performed to retrieve the same set of search results.
  2775. </dd></dl>
  2776. </dd><dd> <code>"example"</code>
  2777. <dl><dd>   Represents a search query that can be performed to demonstrate the search engine.
  2778. </dd></dl>
  2779. </dd><dd> <code>"related"</code>
  2780. <dl><dd>   Represents a search query that can be performed to retrieve similar but different search results.
  2781. </dd></dl>
  2782. </dd><dd> <code>"correction"</code>
  2783. <dl><dd>   Represents a search query that can be performed to improve the result set, such as with a spelling correction.
  2784. </dd></dl>
  2785. </dd><dd> <code>"subset"</code>
  2786. <dl><dd>   Represents a search query that will narrow the current set of search results.
  2787. </dd></dl>
  2788. </dd><dd> <code>"superset"</code>
  2789. <dl><dd>  Represents a search query that will broaden the current set of search results.
  2790. </dd></dl>
  2791. </dd></dl>
  2792. <p><br>
  2793. <i>Example of a local role value:</i>
  2794. </p>
  2795. <pre> &lt;Query role="related"
  2796.        title="A related search"
  2797.        searchTerms="tiger" /&gt;
  2798. </pre>
  2799. <a name="Fully_qualified_role_values"></a><h4> <span class="mw-headline"> Fully qualified role values </span></h4>
  2800. <p>Fully qualified role values are preceded by a prefix.  Fully qualified role values are associated with the namespace identified by the prefix on the containing Query element or ancestor elements.
  2801. </p><p><i>Example of a fully qualified role value:</i>
  2802. </p>
  2803. <pre> &lt;Query xmlns:custom="http://example.com/opensearchextensions/1.0/"
  2804.        role="custom:synonym"
  2805.        title="Synonyms of &#039;cat&#039;"
  2806.        searchTerms="feline" /&gt;
  2807. </pre>
  2808. <a name="OpenSearch_response_elements"></a><h2> <span class="mw-headline"> OpenSearch response elements </span></h2>
  2809. <p>The OpenSearch response elements can be used by search engines to augment existing XML formats with search-related metadata.
  2810. </p><p><i>OpenSearch response elements are typically found augmenting search results returned in list-based XML syndication formats, such as RSS 2.0 and Atom 1.0, but may be used in other contexts without restriction.</i>
  2811. </p>
  2812. <a name="Examples_of_OpenSearch_responses"></a><h3> <span class="mw-headline"> Examples of OpenSearch responses </span></h3>
  2813. <a name="Example_of_OpenSearch_response_elements_in_RSS_2.0"></a><h4> <span class="mw-headline"> Example of OpenSearch response elements in RSS 2.0 </span></h4>
  2814. <p><i>Example of a page of search results in the RSS 2.0 format:</i>
  2815. </p>
  2816. <pre> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  2817. &lt;rss version="2.0"
  2818.      xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"
  2819.      xmlns:atom="http://www.w3.org/2005/Atom"&gt;
  2820.   &lt;channel&gt;
  2821.     &lt;title&gt;Example.com Search: New York history&lt;/title&gt;
  2822.     &lt;link&gt;http://example.com/New+York+history&lt;/link&gt;
  2823.     &lt;description&gt;Search results for "New York history" at Example.com&lt;/description&gt;
  2824.     &lt;opensearch:totalResults&gt;4230000&lt;/opensearch:totalResults&gt;
  2825.     &lt;opensearch:startIndex&gt;21&lt;/opensearch:startIndex&gt;
  2826.     &lt;opensearch:itemsPerPage&gt;10&lt;/opensearch:itemsPerPage&gt;
  2827.     &lt;atom:link rel="search" type="application/opensearchdescription+xml" href="http://example.com/opensearchdescription.xml"/&gt;
  2828.     &lt;opensearch:Query role="request" searchTerms="New York History" startPage="1" /&gt;
  2829.     &lt;item&gt;
  2830.       &lt;title&gt;New York History&lt;/title&gt;
  2831.       &lt;link&gt;http://www.columbia.edu/cu/lweb/eguids/amerihist/nyc.html&lt;/link&gt;
  2832.       &lt;description&gt;
  2833.         ... Harlem.NYC - A virtual tour and information on
  2834.         businesses ...  with historic photos of Columbia&#039;s own New York
  2835.         neighborhood ... Internet Resources for the City&#039;s History. ...
  2836.       &lt;/description&gt;
  2837.     &lt;/item&gt;
  2838.   &lt;/channel&gt;
  2839. &lt;/rss&gt;
  2840. </pre>
  2841. <a name="Example_of_OpenSearch_response_elements_in_Atom_1.0"></a><h4> <span class="mw-headline"> Example of OpenSearch response elements in Atom 1.0 </span></h4>
  2842. <p><i>Example of a page of search results in the Atom 1.0 format:</i>
  2843. </p>
  2844. <pre> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  2845. &lt;feed xmlns="http://www.w3.org/2005/Atom"
  2846.       xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"&gt;
  2847.   &lt;title&gt;Example.com Search: New York history&lt;/title&gt;
  2848.   &lt;link href="http://example.com/New+York+history"/&gt;
  2849.   &lt;updated&gt;2003-12-13T18:30:02Z&lt;/updated&gt;
  2850.   &lt;author&gt;
  2851.     &lt;name&gt;Example.com, Inc.&lt;/name&gt;
  2852.   &lt;/author&gt;
  2853.   &lt;id&gt;urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6&lt;/id&gt;
  2854.   &lt;opensearch:totalResults&gt;4230000&lt;/opensearch:totalResults&gt;
  2855.   &lt;opensearch:startIndex&gt;21&lt;/opensearch:startIndex&gt;
  2856.   &lt;opensearch:itemsPerPage&gt;10&lt;/opensearch:itemsPerPage&gt;
  2857.   &lt;opensearch:Query role="request" searchTerms="New York History" startPage="1" /&gt;
  2858.   &lt;link rel="alternate" href="http://example.com/New+York+History?pw=3" type="text/html"/&gt;
  2859.   &lt;link rel="self" href="http://example.com/New+York+History?pw=3&amp;amp;format=atom" type="application/atom+xml"/&gt;
  2860.   &lt;link rel="first" href="http://example.com/New+York+History?pw=1&amp;amp;format=atom" type="application/atom+xml"/&gt;
  2861.   &lt;link rel="previous" href="http://example.com/New+York+History?pw=2&amp;amp;format=atom" type="application/atom+xml"/&gt;
  2862.   &lt;link rel="next" href="http://example.com/New+York+History?pw=4&amp;amp;format=atom" type="application/atom+xml"/&gt;
  2863.   &lt;link rel="last" href="http://example.com/New+York+History?pw=42299&amp;amp;format=atom" type="application/atom+xml"/&gt;
  2864.   &lt;link rel="search" type="application/opensearchdescription+xml" href="http://example.com/opensearchdescription.xml"/&gt;
  2865.   &lt;entry&gt;
  2866.     &lt;title&gt;New York History&lt;/title&gt;
  2867.     &lt;link href="http://www.columbia.edu/cu/lweb/eguids/amerihist/nyc.html"/&gt;
  2868.     &lt;id&gt;urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a&lt;/id&gt;
  2869.     &lt;updated&gt;2003-12-13T18:30:02Z&lt;/updated&gt;
  2870.     &lt;content type="text"&gt;
  2871.       ... Harlem.NYC - A virtual tour and information on
  2872.       businesses ...  with historic photos of Columbia&#039;s own New York
  2873.       neighborhood ... Internet Resources for the City&#039;s History. ...
  2874.     &lt;/content&gt;
  2875.   &lt;/entry&gt;
  2876. &lt;/feed&gt;
  2877. </pre>
  2878. <a name="Elements"></a><h3> <span class="mw-headline"> Elements </span></h3>
  2879. <a name="The_.22totalResults.22_element"></a><h4> <span class="mw-headline"> The "totalResults" element </span></h4>
  2880. <p>The number of search results available for the current search.
  2881. </p><p><i>If the totalResults element does not appear on the page then the search client should consider the current page to be the last page of search results.</i>
  2882. </p>
  2883. <dl><dd> Restrictions: The value must be a non-negative integer.
  2884. </dd><dd> Default: The default value is equal to the offset index of the last search result on the current page.
  2885. </dd><dd> Requirements: The element may appear zero or one time.
  2886. </dd></dl>
  2887. <p><i>Example:</i>
  2888. </p>
  2889. <pre> &lt;totalResults&gt;492420&lt;/totalResults&gt;
  2890. </pre>
  2891. <a name="The_.22startIndex.22_element"></a><h4> <span class="mw-headline"> The "startIndex" element </span></h4>
  2892. <p>The index of the first search result in the current set of search results.
  2893. </p><p><i>If the startIndex element does not appear on the page then the search client should consider the current page to be the first page of search results.</i>
  2894. </p>
  2895. <dl><dd> Restrictions: The value must an integer.
  2896. </dd><dd> Default: The default value is equal to the value of the "indexOffset" attribute of the <a href="#The_.22Url.22_element" title="">"Url" element"</a> in the <a href="#OpenSearch_description_document" title="">OpenSearch description document</a>.
  2897. </dd><dd> Requirements: The element may appear zero or one time.
  2898. </dd></dl>
  2899. <p><i>Example:</i>
  2900. </p>
  2901. <pre> &lt;startIndex&gt;11&lt;/startIndex&gt;
  2902. </pre>
  2903. <a name="The_.22itemsPerPage.22_element"></a><h4> <span class="mw-headline"> The "itemsPerPage" element </span></h4>
  2904. <p>The number of search results returned per page.
  2905. </p><p><i>If the itemsPerPage element does not appear on the page then the search client should use the number of items of the current page as the default page size.</i>
  2906. </p>
  2907. <dl><dd> Restrictions: The value must a non-negative integer.
  2908. </dd><dd> Default: The default value is equal to the number of search results on the current page.
  2909. </dd><dd> Requirements: The element may appear zero or one time.
  2910. </dd></dl>
  2911. <p><i>Example:</i>
  2912. </p>
  2913. <pre> &lt;itemsPerPage&gt;10&lt;/itemsPerPage&gt;
  2914. </pre>
  2915. <a name="The_.22Query.22_element_3"></a><h4> <span class="mw-headline"> The "Query" element </span></h4>
  2916. <p>Defines a search query that can be performed by search clients.   Please see the <a href="#OpenSearch_Query_element" title="">OpenSearch Query element</a> specification for more information.
  2917. </p><p><i>Search results should include a Query element of type="request" that can be used to recreate the search request that generate the current search response.</i>
  2918. </p>
  2919. <dl><dd> Requirements: The element may appear zero or more times.
  2920. </dd></dl>
  2921. <p><i>Example:</i>
  2922. </p>
  2923. <pre> &lt;Query role="request" searchTerms="cat" /&gt;
  2924. </pre>
  2925. <a name="Response_metadata_in_HTML.2FXHTML"></a><h3> <span class="mw-headline"> Response metadata in HTML/XHTML </span></h3>
  2926. <p>OpenSearch response metadata may be included in well-formed HTML/XHTML via the <a href="http://www.w3.org/TR/1999/REC-html401-19991224/struct/global.html#h-7.4.4.2" class="external text" title="http://www.w3.org/TR/1999/REC-html401-19991224/struct/global.html#h-7.4.4.2" rel="nofollow">HTML 4.0.1 "meta" element</a>.
  2927. </p><p>The following meta element "name" attribute values are recognized under the profile associated with the <a href="#Namespace" title="">OpenSearch 1.1 namespace</a>:
  2928. </p>
  2929. <dl><dd> <code>"totalResults"</code> - Corresponds to value of the <a href="#The_.22totalResults.22_element" title="">"totalResults" element</a>.
  2930. </dd><dd> <code>"startIndex"</code> - Corresponds to value of the <a href="#The_.22startIndex.22_element" title="">"startIndex" element</a>.
  2931. </dd><dd> <code>"itemsPerPage"</code> - Corresponds to value of the <a href="#The_.22itemsPerPage.22_element" title="">"itemsPerPage" element</a>.
  2932. </dd></dl>
  2933. <p><i>Example of a page of search results in the XHTML 1.0 format:</i>
  2934. </p>
  2935. <pre> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  2936. &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2937.    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  2938. &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  2939.   &lt;head profile="http://a9.com/-/spec/opensearch/1.1/" &gt;
  2940.     &lt;title&gt;Example.com Search: New York history&lt;/title&gt;
  2941.     &lt;link rel="search"
  2942.           type="application/opensearchdescription+xml"
  2943.           href="http://example.com/opensearchdescription.xml"
  2944.           title="Example.com Web Search" /&gt;
  2945.     &lt;meta name="totalResults" content="4230000"/&gt;
  2946.     &lt;meta name="startIndex" content"1"/&gt;
  2947.     &lt;meta name="itemsPerPage" content="10"/&gt;
  2948.   &lt;/head&gt;
  2949.   &lt;body&gt;
  2950.      &lt;ul&gt;
  2951.        &lt;li&gt;
  2952.          &lt;a href="http://www.columbia.edu/cu/lweb/eguids/amerihist/nyc.html"&gt;
  2953.            New York History
  2954.          &lt;/a&gt;
  2955.          &lt;div&gt;
  2956.            ... Harlem.NYC - A virtual tour and information on
  2957.            businesses ...  with historic photos of Columbia&#039;s own New York
  2958.            neighborhood ... Internet Resources for the City&#039;s History. ...
  2959.          &lt;/div&gt;
  2960.        &lt;/li&gt;
  2961.        &lt;!-- ... --&gt;
  2962.      &lt;/ul&gt;
  2963.    &lt;/body&gt;
  2964. &lt;/html&gt;
  2965. </pre>
  2966. <a name="Author"></a><h2> <span class="mw-headline"> Author </span></h2>
  2967. <p>DeWitt Clinton &lt;[email protected]&gt;
  2968. </p>
  2969. <a name="Contributors"></a><h2> <span class="mw-headline"> Contributors </span></h2>
  2970. <p>Joel Tesler &lt;[email protected]&gt;, Michael Fagan &lt;[email protected]&gt;, Joe Gregorio &lt;[email protected]&gt;, Aaron Sauve &lt;[email protected]&gt;, James Snell &lt;[email protected]&gt;
  2971. </p>
  2972. <a name="License"></a><h2> <span class="mw-headline"> License </span></h2>
  2973. <p>This document is made available by <a href="http://a9.com" class="external text" title="http://a9.com" rel="nofollow">A9.com</a> subject to the terms of the <a href="http://creativecommons.org/licenses/by-sa/2.5/" class="external text" title="http://creativecommons.org/licenses/by-sa/2.5/" rel="nofollow">Creative Commons Attribution-ShareAlike 2.5 License</a>.
  2974. </p><p><a rel="nofollow" href="https://www.askapache.com/seo/opensearch-description-document/">OpenSearch description document</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  2975. ]]></content:encoded>
  2976. <wfw:commentRss>https://www.askapache.com/seo/opensearch-description-document/feed/</wfw:commentRss>
  2977. <slash:comments>0</slash:comments>
  2978. </item>
  2979. <item>
  2980. <title>Better, Faster, Stronger gethostbyaddr</title>
  2981. <link>https://www.askapache.com/php/better-faster-stronger-gethostbyaddr/</link>
  2982. <comments>https://www.askapache.com/php/better-faster-stronger-gethostbyaddr/#respond</comments>
  2983. <pubDate>Fri, 22 Jul 2016 05:33:14 +0000</pubDate>
  2984. <dc:creator><![CDATA[AskApache]]></dc:creator>
  2985. <category><![CDATA[PHP]]></category>
  2986.  
  2987. <guid isPermaLink="false">https://www.askapache.com/?p=9479</guid>
  2988. <description><![CDATA[<p><a rel="nofollow" href="https://www.askapache.com/php/better-faster-stronger-gethostbyaddr/">Better, Faster, Stronger gethostbyaddr</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  2989. ]]></description>
  2990. <content:encoded><![CDATA[<p>Wow.  where queries must be fast and only consist of a single request followed by a single reply packet</p>
  2991. <ol>
  2992. <li><a href="http://en.wikipedia.org/wiki/User_Datagram_Protocol">User_Datagram_Protocol</a></li>
  2993. <li><a href="http://en.wikipedia.org/wiki/Domain_Name_System">Domain_Name_System</a></li>
  2994. <li><a href="http://technet.microsoft.com/en-us/library/dd197470%28v=ws.10%29.aspx">http://technet.microsoft.com/en-us/library/dd197470%28v=ws.10%29.aspx</a></li>
  2995. <li><a href="http://tools.ietf.org/html/rfc1035">http://tools.ietf.org/html/rfc1035</a></li>
  2996. <li><a href="http://perplexed.co.uk/948_dns_message_format.htm">http://perplexed.co.uk/948_dns_message_format.htm</a></li>
  2997. <li><a href="http://pear.php.net/package/Net_DNS2/">http://pear.php.net/package/Net_DNS2/</a></li>
  2998. </ol>
  2999.  
  3000. <blockquote>
  3001. Reverse lookup
  3002.  
  3003. A reverse lookup is a query of the DNS for domain names when the IP address is known. Multiple domain names may be associated with an IP address. The DNS stores IP addresses in the form of domain names as specially formatted names in pointer (PTR) records within the infrastructure top-level domain arpa. For IPv4, the domain is in-addr.arpa. For IPv6, the reverse lookup domain is ip6.arpa. The IP address is represented as a name in reverse-ordered octet representation for IPv4, and reverse-ordered nibble representation for IPv6.
  3004.  
  3005. When performing a reverse lookup, the DNS client converts the address into these formats before querying the name for a PTR record following the delegation chain as for any DNS query. For example, assuming the IPv4 address 208.80.152.2 is assigned to Wikimedia, it is represented as a DNS name in reverse order: 2.152.80.208.in-addr.arpa. When the DNS resolver gets a pointer (PTR) request, it begins by querying the root servers, which point to the servers of American Registry for Internet Numbers (ARIN) for the 208.in-addr.arpa zone. ARIN's servers delegate 152.80.208.in-addr.arpa to Wikimedia to which the resolver sends another query for 2.152.80.208.in-addr.arpa, which results in an authoritative response.
  3006. </blockquote>
  3007.  
  3008.  
  3009.  
  3010. <div class="ephpcode"><code><span class="epc1"><span class="epc3"></span><span class="epc5">function </span><span class="epc3">get_hostbyaddr</span><span class="epc5">( </span><span class="epc3">$ip</span><span class="epc5">, </span><span class="epc3">$dns </span><span class="epc5">= </span><span class="epc6">'8.8.8.8'</span><span class="epc5">, </span><span class="epc3">$timeout </span><span class="epc5">= </span><span class="epc3">1 </span><span class="epc5">) {<br />  </span><span class="epc3">ISCLOG</span><span class="epc5">::</span><span class="epc3">ti</span><span class="epc5">(</span><span class="epc3">$ip</span><span class="epc5">);<br />  <br />  static </span><span class="epc3">$ips </span><span class="epc5">= array();<br />  <br />  if ( isset( </span><span class="epc3">$ips</span><span class="epc5">[ </span><span class="epc3">$ip </span><span class="epc5">] ) ) return </span><span class="epc3">$ips</span><span class="epc5">[ </span><span class="epc3">$ip </span><span class="epc5">];<br />  else </span><span class="epc3">$ips</span><span class="epc5">[ </span><span class="epc3">$ip </span><span class="epc5">] = </span><span class="epc3">$ip</span><span class="epc5">;<br />  <br />  </span><span class="epc2">// random transaction number (for routers etc to get the reply back)<br />  </span><span class="epc3">$tx </span><span class="epc5">= </span><span class="epc3">rand</span><span class="epc5">( </span><span class="epc3">10</span><span class="epc5">, </span><span class="epc3">77 </span><span class="epc5">) . </span><span class="epc6">"\1\0\0\1\0\0\0\0\0\0"</span><span class="epc5">;<br />  <br />  </span><span class="epc2">// octals in the array, keys are strlen of bit<br />  </span><span class="epc3">$bitso </span><span class="epc5">= array( </span><span class="epc6">""</span><span class="epc5">, </span><span class="epc6">"\1"</span><span class="epc5">, </span><span class="epc6">"\2"</span><span class="epc5">, </span><span class="epc6">"\3" </span><span class="epc5">);<br />  </span><span class="epc3">$arpa </span><span class="epc5">= </span><span class="epc6">''</span><span class="epc5">;<br />  foreach( </span><span class="epc3">array_reverse</span><span class="epc5">( </span><span class="epc3">explode</span><span class="epc5">( </span><span class="epc6">'.'</span><span class="epc5">, </span><span class="epc3">$ip </span><span class="epc5">) ) as </span><span class="epc3">$bit </span><span class="epc5">) {<br />    </span><span class="epc3">$arpa </span><span class="epc5">.= </span><span class="epc3">$bit </span><span class="epc5">. </span><span class="epc6">'.'</span><span class="epc5">;<br />    </span><span class="epc3">$l </span><span class="epc5">= </span><span class="epc3">strlen</span><span class="epc5">( </span><span class="epc3">$bit </span><span class="epc5">);<br />    </span><span class="epc3">$tx </span><span class="epc5">.= </span><span class="epc6">"</span><span class="epc5">{</span><span class="epc3">$bitso</span><span class="epc5">[</span><span class="epc3">$l</span><span class="epc5">]}</span><span class="epc6">" </span><span class="epc5">. </span><span class="epc3">$bit</span><span class="epc5">;<br />  }<br />  </span><span class="epc3">$arpa </span><span class="epc5">.= </span><span class="epc6">'in-addr.arpa'</span><span class="epc5">;<br />  <br />  </span><span class="epc2">// and the final bit of the request<br />  </span><span class="epc3">$tx </span><span class="epc5">.= </span><span class="epc6">"\7in-addr\4arpa\0\0\x0C\0\1"</span><span class="epc5">;<br /><br />  </span><span class="epc2">// create UDP socket<br />  </span><span class="epc3">$errno </span><span class="epc5">= </span><span class="epc3">$errstr </span><span class="epc5">= </span><span class="epc3">0</span><span class="epc5">;<br />  </span><span class="epc3">$fp </span><span class="epc5">= </span><span class="epc3">fsockopen</span><span class="epc5">( </span><span class="epc6">"udp://</span><span class="epc5">{</span><span class="epc3">$dns</span><span class="epc5">}</span><span class="epc6">"</span><span class="epc5">, </span><span class="epc3">53</span><span class="epc5">, </span><span class="epc3">$errno</span><span class="epc5">, </span><span class="epc3">$errstr</span><span class="epc5">, </span><span class="epc3">0.5 </span><span class="epc5">);<br />  if( ! </span><span class="epc3">$fp </span><span class="epc5">|| ! </span><span class="epc3">is_resource</span><span class="epc5">( </span><span class="epc3">$fp </span><span class="epc5">) ) return ( </span><span class="epc3">$ips</span><span class="epc5">[ </span><span class="epc3">$ip </span><span class="epc5">] = </span><span class="epc3">$ip </span><span class="epc5">);<br />  <br />  <br />  if( </span><span class="epc3">function_exists</span><span class="epc5">( </span><span class="epc6">'socket_set_timeout' </span><span class="epc5">) ) {<br />    </span><span class="epc3">socket_set_timeout</span><span class="epc5">( </span><span class="epc3">$fp</span><span class="epc5">, </span><span class="epc3">$timeout </span><span class="epc5">);<br />  } elseif ( </span><span class="epc3">function_exists</span><span class="epc5">( </span><span class="epc6">'stream_set_timeout' </span><span class="epc5">) ) {<br />    </span><span class="epc3">stream_set_timeout</span><span class="epc5">( </span><span class="epc3">$fp</span><span class="epc5">, </span><span class="epc3">$timeout </span><span class="epc5">);<br />  }<br />  <br />  <br /><br />  </span><span class="epc2">// send our request (and store request size so we can cheat later)<br />  </span><span class="epc3">$tx_size </span><span class="epc5">= </span><span class="epc3">fwrite</span><span class="epc5">( </span><span class="epc3">$fp</span><span class="epc5">, </span><span class="epc3">$tx </span><span class="epc5">);<br />  </span><span class="epc3">$max_rx </span><span class="epc5">= </span><span class="epc3">$tx_size </span><span class="epc5">* </span><span class="epc3">7</span><span class="epc5">;<br />  <br />  </span><span class="epc3">$start </span><span class="epc5">= </span><span class="epc3">time</span><span class="epc5">();<br />  </span><span class="epc3">$rx_size </span><span class="epc5">= </span><span class="epc3">$res_len </span><span class="epc5">= </span><span class="epc3">$stop_at </span><span class="epc5">= </span><span class="epc3">0</span><span class="epc5">;<br />  </span><span class="epc3">$rx </span><span class="epc5">= </span><span class="epc6">''</span><span class="epc5">;<br />  <br />  while ( <br />      (<br />        ( </span><span class="epc3">$stop_at </span><span class="epc5">&gt; </span><span class="epc3">0 </span><span class="epc5">&amp;&amp; </span><span class="epc3">$rx_size </span><span class="epc5">&lt; </span><span class="epc3">$stop_at </span><span class="epc5">) || </span><span class="epc3">$stop_at </span><span class="epc5">== </span><span class="epc3">0<br />      </span><span class="epc5">)<br />      &amp;&amp; ! </span><span class="epc3">feof</span><span class="epc5">( </span><span class="epc3">$fp </span><span class="epc5">)<br />      &amp;&amp; </span><span class="epc3">$rx_size </span><span class="epc5">&lt; </span><span class="epc3">$max_rx<br />      </span><span class="epc5">&amp;&amp; ( ( </span><span class="epc3">time</span><span class="epc5">() - </span><span class="epc3">$start </span><span class="epc5">) &lt; </span><span class="epc3">$timeout </span><span class="epc5">)<br />      &amp;&amp; (</span><span class="epc3">$b </span><span class="epc5">= </span><span class="epc3">fread</span><span class="epc5">( </span><span class="epc3">$fp</span><span class="epc5">, </span><span class="epc3">1 </span><span class="epc5">) ) !== </span><span class="epc3">false<br />  </span><span class="epc5">) {<br />    </span><span class="epc3">$rx_size</span><span class="epc5">++;<br />    </span><span class="epc3">$rx </span><span class="epc5">.= </span><span class="epc3">$b</span><span class="epc5">;<br /><br />    if ( </span><span class="epc3">$stop_at </span><span class="epc5">== </span><span class="epc3">0 </span><span class="epc5">&amp;&amp; </span><span class="epc3">$res_len </span><span class="epc5">== </span><span class="epc3">0 </span><span class="epc5">&amp;&amp; ( </span><span class="epc3">$rx_size </span><span class="epc5">&gt; </span><span class="epc3">$tx_size </span><span class="epc5">+ </span><span class="epc3">12 </span><span class="epc5">) ) {<br />      </span><span class="epc3">$res_len </span><span class="epc5">= </span><span class="epc3">hexdec</span><span class="epc5">( </span><span class="epc3">bin2hex</span><span class="epc5">( </span><span class="epc3">substr</span><span class="epc5">( </span><span class="epc3">$rx</span><span class="epc5">, </span><span class="epc3">$tx_size </span><span class="epc5">+ </span><span class="epc3">11</span><span class="epc5">, </span><span class="epc3">1 </span><span class="epc5">) ) );<br />      </span><span class="epc3">$stop_at </span><span class="epc5">= ( </span><span class="epc3">$res_len </span><span class="epc5">+ </span><span class="epc3">$tx_size </span><span class="epc5">+ </span><span class="epc3">12 </span><span class="epc5">);<br />    }<br />  }<br />  <br />  </span><span class="epc3">$response_length </span><span class="epc5">= </span><span class="epc3">hexdec</span><span class="epc5">( </span><span class="epc3">bin2hex</span><span class="epc5">( </span><span class="epc3">substr</span><span class="epc5">( </span><span class="epc3">$rx</span><span class="epc5">, </span><span class="epc3">$tx_size </span><span class="epc5">+ </span><span class="epc3">11</span><span class="epc5">, </span><span class="epc3">1 </span><span class="epc5">) ) );<br />  </span><span class="epc2">/*<br />  echo "[response_length]: {$response_length}  C:" .   bin2hex( substr( $rx, $tx_size + $response_length + 11, 1 )) . "  B:" . bin2hex( substr( $rx, -1 ) ) . "\n";<br />  echo "[tx: $tx_size bytes]  \n" . ISCLOG::hexdump($tx,array('ascii_len'=&gt;50))."\n";<br />  echo "[rx: {$rx_size} bytes]\n" . ISCLOG::hexdump($rx,array('ascii_len'=&gt;50))."\n";<br />  */<br /><br />  // hope we get a reply<br />  </span><span class="epc5">if ( </span><span class="epc3">is_resource</span><span class="epc5">( </span><span class="epc3">$fp </span><span class="epc5">) ) </span><span class="epc3">fclose</span><span class="epc5">( </span><span class="epc3">$fp </span><span class="epc5">);<br /><br />  </span><span class="epc2">// if empty response or bad response, return original ip<br />  </span><span class="epc5">if ( empty( </span><span class="epc3">$rx </span><span class="epc5">) || </span><span class="epc3">bin2hex</span><span class="epc5">( </span><span class="epc3">substr</span><span class="epc5">( </span><span class="epc3">$rx</span><span class="epc5">, </span><span class="epc3">$tx_size </span><span class="epc5">+ </span><span class="epc3">2</span><span class="epc5">, </span><span class="epc3">2 </span><span class="epc5">) ) != </span><span class="epc6">'000c' </span><span class="epc5">|| </span><span class="epc3">bin2hex</span><span class="epc5">( </span><span class="epc3">substr</span><span class="epc5">( </span><span class="epc3">$rx</span><span class="epc5">, -</span><span class="epc3">1 </span><span class="epc5">) ) != </span><span class="epc6">'00' </span><span class="epc5">) {<br />    </span><span class="epc2">//$hostip = @gethostbyname( $ip );<br /><br />    </span><span class="epc5">echo </span><span class="epc6">"!!! [</span><span class="epc5">{</span><span class="epc3">$ip</span><span class="epc5">}</span><span class="epc6">  - tx:</span><span class="epc5">{</span><span class="epc3">$tx_size</span><span class="epc5">}</span><span class="epc6"> rx:</span><span class="epc5">{</span><span class="epc3">$rx_size</span><span class="epc5">}</span><span class="epc6"> stop:</span><span class="epc5">{</span><span class="epc3">$stop_at</span><span class="epc5">}</span><span class="epc6"> res_len:</span><span class="epc5">{</span><span class="epc3">$res_len</span><span class="epc5">}</span><span class="epc6"> ]  " </span><span class="epc5">. <br />    </span><span class="epc6">" 000c:" </span><span class="epc5">. </span><span class="epc3">bin2hex</span><span class="epc5">( </span><span class="epc3">substr</span><span class="epc5">( </span><span class="epc3">$rx</span><span class="epc5">, </span><span class="epc3">$tx_size </span><span class="epc5">+ </span><span class="epc3">2</span><span class="epc5">, </span><span class="epc3">2 </span><span class="epc5">) ) . </span><span class="epc6">" 00:" </span><span class="epc5">. </span><span class="epc3">bin2hex</span><span class="epc5">( </span><span class="epc3">substr</span><span class="epc5">( </span><span class="epc3">$rx</span><span class="epc5">, -</span><span class="epc3">1 </span><span class="epc5">) ) . </span><span class="epc6">"\n"</span><span class="epc5">;<br />    </span><span class="epc2">//echo ISCLOG::hexdump($rx,array('ascii_len'=&gt;50))."\n";<br />    //echo ISCLOG::hexdump($tx,array('ascii_len'=&gt;50))."\n" . ISCLOG::hexdump($rx,array('ascii_len'=&gt;50))."\n";<br />    //$ip = ( $hostip == $ip ) ? $ip : long2ip( ip2long( $ip ) );<br />  <br />    </span><span class="epc5">return ( </span><span class="epc3">$ips</span><span class="epc5">[ </span><span class="epc3">$ip </span><span class="epc5">] = </span><span class="epc3">$ip </span><span class="epc5">);<br />  }<br />    <br />  </span><span class="epc2">// set up our variables<br />  </span><span class="epc3">$host </span><span class="epc5">= </span><span class="epc6">''</span><span class="epc5">;<br />  </span><span class="epc3">$len </span><span class="epc5">= </span><span class="epc3">$loops </span><span class="epc5">= </span><span class="epc3">0</span><span class="epc5">;<br />  <br />  </span><span class="epc2">// set our pointer at the beginning of the hostname uses the request size from earlier rather than work it out<br />  </span><span class="epc3">$pos </span><span class="epc5">= </span><span class="epc3">$tx_size </span><span class="epc5">+ </span><span class="epc3">12</span><span class="epc5">;<br />  do {<br />    </span><span class="epc3">$myc </span><span class="epc5">= </span><span class="epc3">substr</span><span class="epc5">( </span><span class="epc3">$rx</span><span class="epc5">, </span><span class="epc3">$pos</span><span class="epc5">, </span><span class="epc3">1 </span><span class="epc5">);<br />    <br />    </span><span class="epc2">// get segment size<br />    </span><span class="epc5">if ( </span><span class="epc3">strlen</span><span class="epc5">( </span><span class="epc3">$myc </span><span class="epc5">) &gt; </span><span class="epc3">0 </span><span class="epc5">) </span><span class="epc3">$len </span><span class="epc5">= </span><span class="epc3">unpack</span><span class="epc5">( </span><span class="epc6">'c'</span><span class="epc5">, </span><span class="epc3">$myc </span><span class="epc5">);<br />    <br />    </span><span class="epc2">// null terminated string, so length 0 = finished - return the hostname, without the trailing .<br />    </span><span class="epc5">if ( </span><span class="epc3">$len</span><span class="epc5">[</span><span class="epc3">1</span><span class="epc5">] == </span><span class="epc3">0 </span><span class="epc5">) return ( </span><span class="epc3">$ips</span><span class="epc5">[ </span><span class="epc3">$ip </span><span class="epc5">] = </span><span class="epc3">substr</span><span class="epc5">( </span><span class="epc3">$host</span><span class="epc5">, </span><span class="epc3">0</span><span class="epc5">, -</span><span class="epc3">1 </span><span class="epc5">) );<br />    <br />    </span><span class="epc2">// add segment to our host<br />    </span><span class="epc3">$host </span><span class="epc5">.= </span><span class="epc3">substr</span><span class="epc5">( </span><span class="epc3">$rx</span><span class="epc5">, </span><span class="epc3">$pos </span><span class="epc5">+ </span><span class="epc3">1</span><span class="epc5">, </span><span class="epc3">abs</span><span class="epc5">( </span><span class="epc3">$len</span><span class="epc5">[</span><span class="epc3">1</span><span class="epc5">] ) ) . </span><span class="epc6">'.'</span><span class="epc5">;<br />    </span><span class="epc2">//ISCLOG::l($loops . ': '. 'pos:'.$pos. ' len:' . $len[1] . ' ' . $host);<br /><br />    // move pointer on to the next segment<br />    </span><span class="epc3">$pos </span><span class="epc5">+= </span><span class="epc3">$len</span><span class="epc5">[</span><span class="epc3">1</span><span class="epc5">] + </span><span class="epc3">1</span><span class="epc5">;<br />    <br />  } while ( </span><span class="epc3">$len</span><span class="epc5">[</span><span class="epc3">1</span><span class="epc5">] != </span><span class="epc3">0 </span><span class="epc5">&amp;&amp; </span><span class="epc3">$loops</span><span class="epc5">++ &lt; </span><span class="epc3">40 </span><span class="epc5">);<br /><br />  </span><span class="epc2">// return the ip in case <br />  </span><span class="epc5">return ( </span><span class="epc3">$ips</span><span class="epc5">[ </span><span class="epc3">$ip </span><span class="epc5">] = </span><span class="epc3">$ip </span><span class="epc5">);<br />}</span></span></code></div><p><a rel="nofollow" href="https://www.askapache.com/php/better-faster-stronger-gethostbyaddr/">Better, Faster, Stronger gethostbyaddr</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  3011. ]]></content:encoded>
  3012. <wfw:commentRss>https://www.askapache.com/php/better-faster-stronger-gethostbyaddr/feed/</wfw:commentRss>
  3013. <slash:comments>0</slash:comments>
  3014. </item>
  3015. <item>
  3016. <title>Finding Global Memory Hogs in WordPress</title>
  3017. <link>https://www.askapache.com/wordpress/finding-memory-hogs-wordpress/</link>
  3018. <comments>https://www.askapache.com/wordpress/finding-memory-hogs-wordpress/#respond</comments>
  3019. <pubDate>Fri, 22 Jul 2016 05:31:50 +0000</pubDate>
  3020. <dc:creator><![CDATA[AskApache]]></dc:creator>
  3021. <category><![CDATA[WordPress]]></category>
  3022. <category><![CDATA[json_encode]]></category>
  3023. <category><![CDATA[memory]]></category>
  3024. <category><![CDATA[PHP]]></category>
  3025. <category><![CDATA[wordpress]]></category>
  3026.  
  3027. <guid isPermaLink="false">https://www.askapache.com/?p=9546</guid>
  3028. <description><![CDATA[<p><a rel="nofollow" href="https://www.askapache.com/wordpress/finding-memory-hogs-wordpress/">Finding Global Memory Hogs in WordPress</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  3029. ]]></description>
  3030. <content:encoded><![CDATA[<p>It is easy to accidentally pollute the global PHP scope with unneccessary vars, and in some cases these vars are classes or objects, and can be a huge waste of memory per php process.</p>
  3031.  
  3032. <h2>PHP to Find Global Sizes</h2>
  3033. <p>This php will loop through all global vars, then sort them by the strlen of their json_encoded value.</p>
  3034. <div class="ephpcode"><code><span class="epc1"><span class="epc3">$glens </span><span class="epc5">= array();<br />foreach ( </span><span class="epc3">array_keys</span><span class="epc5">( </span><span class="epc3">$GLOBALS </span><span class="epc5">) as </span><span class="epc3">$k </span><span class="epc5">) {<br />    </span><span class="epc3">$glens</span><span class="epc5">[ </span><span class="epc3">mb_strlen</span><span class="epc5">( </span><span class="epc3">json_encode</span><span class="epc5">( </span><span class="epc3">$GLOBALS</span><span class="epc5">[ </span><span class="epc3">$k </span><span class="epc5">], </span><span class="epc3">JSON_UNESCAPED_SLASHES </span><span class="epc5">| </span><span class="epc3">JSON_PARTIAL_OUTPUT_ON_ERROR </span><span class="epc5">| </span><span class="epc3">JSON_UNESCAPED_UNICODE </span><span class="epc5">) ) ] = </span><span class="epc3">$k</span><span class="epc5">;<br />}<br /></span><span class="epc3">krsort</span><span class="epc5">( </span><span class="epc3">$glens </span><span class="epc5">);<br /></span><span class="epc3">var_export</span><span class="epc5">( </span><span class="epc3">$glens </span><span class="epc5">);</span></span></code></div>
  3035.  
  3036.  
  3037.  
  3038. <h3>Sample Output</h3>
  3039. <pre>
  3040. 6788535 =&gt; &#039;GLOBALS&#039;,
  3041. 5615030 =&gt; &#039;wp_object_cache&#039;,
  3042. 2516754 =&gt; &#039;wpdb&#039;,
  3043. 303154 =&gt; &#039;wp_filter&#039;,
  3044. 51323 =&gt; &#039;wp_scripts&#039;,
  3045. 36602 =&gt; &#039;wp_post_types&#039;,
  3046. 14685 =&gt; &#039;wp_taxonomies&#039;,
  3047. 14590 =&gt; &#039;submenu&#039;,
  3048. 14576 =&gt; &#039;wp_registered_widgets&#039;,
  3049. 13426 =&gt; &#039;wpseo_sitemaps&#039;,
  3050. 13111 =&gt; &#039;wp_registered_widget_controls&#039;,
  3051. 10468 =&gt; &#039;wp_rewrite&#039;,
  3052. 10203 =&gt; &#039;AA_DEBUG&#039;,
  3053. 9237 =&gt; &#039;wp_styles&#039;,
  3054. 8861 =&gt; &#039;allowedposttags&#039;,
  3055. 8568 =&gt; &#039;wp_roles&#039;,
  3056. 7017 =&gt; &#039;wp_registered_widget_updates&#039;,
  3057. 5727 =&gt; &#039;menu&#039;,
  3058. 5383 =&gt; &#039;wp_widget_factory&#039;,
  3059. 4355 =&gt; &#039;allowedentitynames&#039;,
  3060. 4300 =&gt; &#039;wp_post_statuses&#039;,
  3061. 3091 =&gt; &#039;userdata&#039;,
  3062. 3003 =&gt; &#039;_SERVER&#039;,
  3063. 2769 =&gt; &#039;_parent_pages&#039;,
  3064. 2658 =&gt; &#039;_wp_admin_css_colors&#039;,
  3065. 2393 =&gt; &#039;_registered_pages&#039;,
  3066. 2283 =&gt; &#039;wp_registered_sidebars&#039;,
  3067. 2106 =&gt; &#039;wp&#039;,
  3068. 1861 =&gt; &#039;_wp_post_type_features&#039;,
  3069. 1477 =&gt; &#039;mb_news_links&#039;,
  3070. 1468 =&gt; &#039;mb_the_brief&#039;,
  3071. 1463 =&gt; &#039;mb_top_stories&#039;,
  3072. 1461 =&gt; &#039;mb_project&#039;,
  3073. 1383 =&gt; &#039;current_screen&#039;,
  3074. 1363 =&gt; &#039;wp_file_descriptions&#039;,
  3075. 1336 =&gt; &#039;wp_locale&#039;,
  3076. 1322 =&gt; &#039;admin_page_hooks&#039;,
  3077. 1137 =&gt; &#039;sidebars_widgets&#039;,
  3078. 1131 =&gt; &#039;wp_query&#039;,
  3079. 1071 =&gt; &#039;shortcode_tags&#039;,
  3080. 1004 =&gt; &#039;BetterRelatedAdmin&#039;,
  3081. 956 =&gt; &#039;merged_filters&#039;,
  3082. 840 =&gt; &#039;wp_actions&#039;,
  3083. 809 =&gt; &#039;relevanssi_variables&#039;,
  3084. 775 =&gt; &#039;l10n&#039;,
  3085. 764 =&gt; &#039;mwm_aalLoader&#039;,
  3086. 754 =&gt; &#039;_wp_deprecated_widgets_callbacks&#039;,
  3087. 654 =&gt; &#039;new_whitelist_options&#039;,
  3088. 591 =&gt; &#039;members&#039;,
  3089. 543 =&gt; &#039;wp_embed&#039;,
  3090. 509 =&gt; &#039;wp_admin_bar&#039;,
  3091. 422 =&gt; &#039;dsq_api&#039;,
  3092. 409 =&gt; &#039;_wp_additional_image_sizes&#039;,
  3093. 376 =&gt; &#039;acf&#039;,
  3094. 344 =&gt; &#039;_REQUEST&#039;,
  3095. 341 =&gt; &#039;_scb_data&#039;,
  3096. 339 =&gt; &#039;allowedtags&#039;,
  3097. 285 =&gt; &#039;month_abbrev&#039;,
  3098. 284 =&gt; &#039;_wp_real_parent_file&#039;,
  3099. 261 =&gt; &#039;month&#039;,
  3100. 226 =&gt; &#039;wp_meta_boxes&#039;,
  3101. 224 =&gt; &#039;_wp_registered_nav_menus&#039;,
  3102. 175 =&gt; &#039;weekday_abbrev&#039;,
  3103. 161 =&gt; &#039;weekday_initial&#039;,
  3104. 133 =&gt; &#039;weekday&#039;,
  3105. 119 =&gt; &#039;_wp_theme_features&#039;,
  3106. 112 =&gt; &#039;_wp_submenu_nopriv&#039;,
  3107. 96 =&gt; &#039;ISCLOG&#039;,
  3108. 87 =&gt; &#039;count&#039;,
  3109. 86 =&gt; &#039;wp_theme_directories&#039;,
  3110. 78 =&gt; &#039;core_menu_positions&#039;,
  3111. 42 =&gt; &#039;custom_post_type_order&#039;,
  3112. 37 =&gt; &#039;akismet_api_host&#039;,
  3113. 36 =&gt; &#039;timestart&#039;,
  3114. 32 =&gt; &#039;wpseo_sitemaps_admin&#039;,
  3115. 31 =&gt; &#039;user_email&#039;,
  3116. 30 =&gt; &#039;args&#039;,
  3117. 28 =&gt; &#039;PHP_SELF&#039;,
  3118. 26 =&gt; &#039;akismet_nonce&#039;,
  3119. 24 =&gt; &#039;members_load&#039;,
  3120. 23 =&gt; &#039;wpseo_admin&#039;,
  3121. 22 =&gt; &#039;hook_name&#039;,
  3122. 20 =&gt; &#039;tinymce_version&#039;,
  3123. 18 =&gt; &#039;hook_suffix&#039;,
  3124. 16 =&gt; &#039;parent_file&#039;,
  3125. 13 =&gt; &#039;title&#039;,
  3126. 12 =&gt; &#039;time_format&#039;,
  3127. 11 =&gt; &#039;is_configured&#039;,
  3128. 10 =&gt; &#039;required_mysql_version&#039;,
  3129. 8 =&gt; &#039;wp_db_version&#039;,
  3130. 7 =&gt; &#039;taxnow&#039;,
  3131. 6 =&gt; &#039;_wp_menu_nopriv&#039;,
  3132. 5 =&gt; &#039;_wp_last_utility_menu&#039;,
  3133. 4 =&gt; &#039;separator_found&#039;,
  3134. 2 =&gt; &#039;show_admin_bar&#039;,
  3135. </pre>
  3136. <p><a rel="nofollow" href="https://www.askapache.com/wordpress/finding-memory-hogs-wordpress/">Finding Global Memory Hogs in WordPress</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  3137. ]]></content:encoded>
  3138. <wfw:commentRss>https://www.askapache.com/wordpress/finding-memory-hogs-wordpress/feed/</wfw:commentRss>
  3139. <slash:comments>0</slash:comments>
  3140. </item>
  3141. <item>
  3142. <title>Apache Logging for Remote Addresses using X-Forwarded-For</title>
  3143. <link>https://www.askapache.com/hosting/x-forwarded-logging-remote_addr/</link>
  3144. <comments>https://www.askapache.com/hosting/x-forwarded-logging-remote_addr/#respond</comments>
  3145. <pubDate>Fri, 22 Jul 2016 05:31:12 +0000</pubDate>
  3146. <dc:creator><![CDATA[AskApache]]></dc:creator>
  3147. <category><![CDATA[Hosting]]></category>
  3148. <category><![CDATA[Htaccess]]></category>
  3149. <category><![CDATA[Apache]]></category>
  3150. <category><![CDATA[F5]]></category>
  3151. <category><![CDATA[HTTPS]]></category>
  3152. <category><![CDATA[SetEnvIf]]></category>
  3153. <category><![CDATA[X-Forwarded-For]]></category>
  3154.  
  3155. <guid isPermaLink="false">https://www.askapache.com/?p=9493</guid>
  3156. <description><![CDATA[<p><a rel="nofollow" href="https://www.askapache.com/hosting/x-forwarded-logging-remote_addr/">Apache Logging for Remote Addresses using X-Forwarded-For</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  3157. ]]></description>
  3158. <content:encoded><![CDATA[
  3159. <pre class="prettyprint lang-config">
  3160. SetEnvIf ^X-Forwarded-For$ ^$ noxforward
  3161. SetEnvIf Remote_Addr "(.+)" xremote=$1
  3162. RequestHeader set X-Forwarded-For %{xremote}e env=noxforward
  3163.  
  3164. LogFormat "%v %h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
  3165. LogFormat "%v %{X-FORWARDED-FOR}i %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" commonvhost
  3166. </pre>
  3167.  
  3168.  
  3169. <h2>LOG Formats and Settings</h2>
  3170. <pre class="prettyprint lang-config">
  3171. #  LOG Formats and Settings {{{2
  3172. # ================================================================================
  3173. SetEnvIf ^X-Forwarded-For$ ^$ noxforward
  3174. SetEnvIf ^X-Forwarded-For$ "(.+)" xforwarded=$1
  3175.  
  3176. SetEnvIf ^X-Cluster-Client-Ip$ ^$ noxclusterip
  3177. SetEnvIf ^X-Cluster-Client-Ip$ "(.+)" xclusterip=$1
  3178.  
  3179. SetEnvIf Remote_Addr ^$ noxremote
  3180. SetEnvIf Remote_Addr "(10\.183\.253\.48)" noxremote
  3181. SetEnvIf Remote_Addr "(.+)" xremote=$1
  3182.  
  3183. #  If the environment variable specified in the env=... argument exists (or if the environment variable does not exist and env=!... is specified) then the action specified by the RequestHeader directive will take effect.
  3184. RequestHeader set X-ISC-IP %{xclusterip}e env=!noxclusterip
  3185. RequestHeader set X-ISC-IP %{xclusterip}e env=!noxremote
  3186. RequestHeader set X-ISC-IP %{xremote}e env=!xclusterip
  3187.  
  3188. LogFormat "%v %h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
  3189. LogFormat "%v %{X-ISC-IP}i %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" commonvhost
  3190. </pre><p><a rel="nofollow" href="https://www.askapache.com/hosting/x-forwarded-logging-remote_addr/">Apache Logging for Remote Addresses using X-Forwarded-For</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  3191. ]]></content:encoded>
  3192. <wfw:commentRss>https://www.askapache.com/hosting/x-forwarded-logging-remote_addr/feed/</wfw:commentRss>
  3193. <slash:comments>0</slash:comments>
  3194. </item>
  3195. <item>
  3196. <title>TMUX</title>
  3197. <link>https://www.askapache.com/hacking/tmux/</link>
  3198. <comments>https://www.askapache.com/hacking/tmux/#respond</comments>
  3199. <pubDate>Tue, 19 Jul 2016 03:04:53 +0000</pubDate>
  3200. <dc:creator><![CDATA[AskApache]]></dc:creator>
  3201. <category><![CDATA[Hacking]]></category>
  3202. <category><![CDATA[Linux]]></category>
  3203. <category><![CDATA[linux.bash]]></category>
  3204. <category><![CDATA[Screen]]></category>
  3205. <category><![CDATA[shell]]></category>
  3206. <category><![CDATA[tmux]]></category>
  3207.  
  3208. <guid isPermaLink="false">https://www.askapache.com/?p=6983</guid>
  3209. <description><![CDATA[<p><a href="https://www.askapache.com/hacking/tmux/" class="IFL"><img src="https://www.askapache.com/s/u.askapache.com/2016/07/penguin-tmux-300x169.png" alt="penguin-tmux" width="300" height="169"  /></a><a class="IFR" href="https://www.askapache.com/s/u.askapache.com/2016/07/archlinux-on-mac.jpg"><img src="https://www.askapache.com/s/u.askapache.com/2016/07/archlinux-on-mac-225x300.jpg" alt="archlinux-on-mac" width="225" height="300" /></a>Stop wasting your lives with Mac Terminals.. or Macs.   Get a real machine and then get a real shell multiplexer!  For many years we all loved GNU Screen, but tmux is by far a better option today.  The only time I am in the shell and not using a multiplexer, is when I'm not on one of my machines. My Arch Linux machines all run URxvt and my .bash_profiles all start tmux automataically, whether in X or single-user mode, tmux is where it's at.<br class="C" /></p>
  3210. <p><a rel="nofollow" href="https://www.askapache.com/hacking/tmux/">TMUX</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  3211. ]]></description>
  3212. <content:encoded><![CDATA[<p>TMUX == GNU Screen x 2.. here is a screenshot from my Arch Linux ThinkPenguin.com laptop back in 2014.  That bg image, taken from the International Space Station is now one of my favorite grub boot bg images.</p>
  3213. <div><img style="max-width:100%; max-height:100%" src="https://www.askapache.com/s/u.askapache.com/2016/07/penguin-tmux.png" alt="penguin-tmux" /></div>
  3214.  
  3215.  
  3216.  
  3217. <h2>tmux usage</h2><a href="https://www.askapache.com/s/u.askapache.com/2016/07/archlinux-on-mac.jpg"><img src="https://www.askapache.com/s/u.askapache.com/2016/07/archlinux-on-mac-225x300.jpg" alt="archlinux-on-mac" width="225" height="300" class="alignnone size-medium wp-image-9896" /></a>
  3218. <p>Note: This is primarily an article of my notes taken from reading the tmux source code.  I'll add some good practical usage another time perhaps.</p>
  3219. <pre>usage: %s [-2lquvV] [-c shell-command] [-f file] [-L socket-name] [-S socket-path] [command [flags]]</pre>
  3220.  
  3221.  
  3222.  
  3223. <h2>tmux.conf</h2>
  3224. <p>Per my usual habit, I downloaded the tmux source code and poured over it for weeks.  The purpose of that wasn't abstract, I work to find and build systems that once built will enable and empower my computing for a long time.  In this case, for me that meant building a super optimized and understood tmux.conf -- here is the one I am using at the moment.  <a href="https://www.askapache.com/s/u.askapache.com/2016/07/tmux-conf.txt" target="_blank">tmux.conf</a></p>
  3225.  
  3226.  
  3227. <h2>Tmux Command Aliases</h2>
  3228. <pre>grep -h &#039;const struct cmd_entry&#039; -A1 cmd-*.c|nobb|grep -v &#039;^const&#039;|grep -v &#039;^\-\-&#039;|trs|nobb| sed &#039;s,^"\([^"]\+\)"\, *"\([^"]\+\)"..*$,\2:&lt;li&gt;&lt;strong&gt;\2&lt;/strong&gt;: \1&lt;/li&gt;,g&#039;|grep -v NULL|sort -g|cut -d&#039;:&#039; -f2-</pre>
  3229. <ul>
  3230. <li><strong>attach</strong>: attach-session</li>
  3231. <li><strong>bind</strong>: bind-key</li>
  3232. <li><strong>breakp</strong>: break-pane</li>
  3233. <li><strong>capturep</strong>: capture-pane</li>
  3234. <li><strong>clearhist</strong>: clear-history</li>
  3235. <li><strong>confirm</strong>: confirm-before</li>
  3236. <li><strong>deleteb</strong>: delete-buffer</li>
  3237. <li><strong>detach</strong>: detach-client</li>
  3238. <li><strong>display</strong>: display-message</li>
  3239. <li><strong>displayp</strong>: display-panes</li>
  3240. <li><strong>findw</strong>: find-window</li>
  3241. <li><strong>has</strong>: has-session</li>
  3242. <li><strong>if</strong>: if-shell</li>
  3243. <li><strong>joinp</strong>: join-pane</li>
  3244. <li><strong>killp</strong>: kill-pane</li>
  3245. <li><strong>killw</strong>: kill-window</li>
  3246. <li><strong>last</strong>: last-window</li>
  3247. <li><strong>lastp</strong>: last-pane</li>
  3248. <li><strong>linkw</strong>: link-window</li>
  3249. <li><strong>loadb</strong>: load-buffer</li>
  3250. <li><strong>lock</strong>: lock-server</li>
  3251. <li><strong>lockc</strong>: lock-client</li>
  3252. <li><strong>locks</strong>: lock-session</li>
  3253. <li><strong>ls</strong>: list-sessions</li>
  3254. <li><strong>lsb</strong>: list-buffers</li>
  3255. <li><strong>lsc</strong>: list-clients</li>
  3256. <li><strong>lscm</strong>: list-commands</li>
  3257. <li><strong>lsk</strong>: list-keys</li>
  3258. <li><strong>lsp</strong>: list-panes</li>
  3259. <li><strong>lsw</strong>: list-windows</li>
  3260. <li><strong>movep</strong>: move-pane</li>
  3261. <li><strong>movew</strong>: move-window</li>
  3262. <li><strong>new</strong>: new-session</li>
  3263. <li><strong>neww</strong>: new-window</li>
  3264. <li><strong>next</strong>: next-window</li>
  3265. <li><strong>nextl</strong>: next-layout</li>
  3266. <li><strong>pasteb</strong>: paste-buffer</li>
  3267. <li><strong>pipep</strong>: pipe-pane</li>
  3268. <li><strong>prev</strong>: previous-window</li>
  3269. <li><strong>prevl</strong>: previous-layout</li>
  3270. <li><strong>refresh</strong>: refresh-client</li>
  3271. <li><strong>rename</strong>: rename-session</li>
  3272. <li><strong>renamew</strong>: rename-window</li>
  3273. <li><strong>resizep</strong>: resize-pane</li>
  3274. <li><strong>respawnp</strong>: respawn-pane</li>
  3275. <li><strong>respawnw</strong>: respawn-window</li>
  3276. <li><strong>rotatew</strong>: rotate-window</li>
  3277. <li><strong>run</strong>: run-shell</li>
  3278. <li><strong>saveb</strong>: save-buffer</li>
  3279. <li><strong>selectl</strong>: select-layout</li>
  3280. <li><strong>selectp</strong>: select-pane</li>
  3281. <li><strong>selectw</strong>: select-window</li>
  3282. <li><strong>send</strong>: send-keys</li>
  3283. <li><strong>set</strong>: set-option</li>
  3284. <li><strong>setb</strong>: set-buffer</li>
  3285. <li><strong>setenv</strong>: set-environment</li>
  3286. <li><strong>setw</strong>: set-window-option</li>
  3287. <li><strong>show</strong>: show-options</li>
  3288. <li><strong>showb</strong>: show-buffer</li>
  3289. <li><strong>showenv</strong>: show-environment</li>
  3290. <li><strong>showmsgs</strong>: show-messages</li>
  3291. <li><strong>showw</strong>: show-window-options</li>
  3292. <li><strong>source</strong>: source-file</li>
  3293. <li><strong>splitw</strong>: split-window</li>
  3294. <li><strong>start</strong>: start-server</li>
  3295. <li><strong>suspendc</strong>: suspend-client</li>
  3296. <li><strong>swapp</strong>: swap-pane</li>
  3297. <li><strong>swapw</strong>: swap-window</li>
  3298. <li><strong>switchc</strong>: switch-client</li>
  3299. <li><strong>unbind</strong>: unbind-key</li>
  3300. <li><strong>unlinkw</strong>: unlink-window</li>
  3301. <li><strong>wait</strong>: wait-for</li>
  3302. <li><strong>info</strong>: server-info</li>
  3303. </ul>
  3304.  
  3305. <h2>Default Templates</h2>
  3306. <dl>
  3307. <dt>CHOOSE_BUFFER_TEMPLATE</dt>
  3308. <dd>Default template for choose-buffer. <pre>"#{line}: #{buffer_size} bytes: #{buffer_sample}"</pre></dd>
  3309. <dt>CHOOSE_CLIENT_TEMPLATE</dt>
  3310. <dd>Default template for choose-client. <pre>"#{client_tty}: #{session_name} [#{client_width}x#{client_height} #{client_termname}]#{?client_utf8, (utf8),}#{?client_readonly, (ro),} (last used #{client_activity_string})"</pre></dd>
  3311. <dt>CHOOSE_TREE_SESSION_TEMPLATE</dt>
  3312. <dd>Default templates for choose-tree. <pre class="prettyprint lang-config">"#{session_name}: #{session_windows} windows#{?session_grouped, (group ,}#{session_group}#{?session_grouped,),}#{?session_attached, (attached),}"</pre></dd>
  3313. <dt>CHOOSE_TREE_WINDOW_TEMPLATE</dt>
  3314. <dd><pre>"#{window_index}: #{window_name}#{window_flags} \"#{pane_title}\""</pre></dd>
  3315. <dt>DISPLAY_MESSAGE_TEMPLATE</dt>
  3316. <dd>Default template for display-message. <pre>"[#{session_name}] #{window_index}:#{window_name}, current pane #{pane_index} - (%H:%M %d-%b-%y)"</pre></dd>
  3317. <dt>FIND_WINDOW_TEMPLATE</dt>
  3318. <dd>Default template for find-window. <pre>"#{window_index}: #{window_name} [#{window_width}x#{window_height}] (#{window_panes} panes) #{window_find_matches}"</pre></dd>
  3319. <dt>LIST_BUFFERS_TEMPLATE</dt>
  3320. <dd>Default template for list-buffers. <pre>"#{line}: #{buffer_size} bytes: \"#{buffer_sample}\""</pre></dd>
  3321. <dt>LIST_CLIENTS_TEMPLATE</dt>
  3322. <dd>Default template for list-clients. <pre>"#{client_tty}: #{session_name} [#{client_width}x#{client_height} #{client_termname}]#{?client_utf8, (utf8),} #{?client_readonly, (ro),}"</pre></dd>
  3323. <dt>LIST_SESSIONS_TEMPLATE</dt>
  3324. <dd>Default template for list-sessions. <pre class="prettyprint lang-config">"#{session_name}: #{session_windows} windows (created #{session_created_string}) [#{session_width}x#{session_height}]#{?session_grouped, (group ,}#{session_group}#{?session_grouped,),}#{?session_attached, (attached),}"</pre></dd>
  3325. <dt>LIST_WINDOWS_TEMPLATE</dt>
  3326. <dd>Default templates for list-windows. <pre>"#{window_index}: #{window_name}#{window_flags} (#{window_panes} panes) [#{window_width}x#{window_height}] [layout #{window_layout}] #{window_id}#{?window_active, (active),}"</pre></dd>
  3327. <dt>LIST_WINDOWS_WITH_SESSION_TEMPLATE</dt>
  3328. <dd><pre>"#{session_name}:#{window_index}: #{window_name}#{window_flags} (#{window_panes} panes) [#{window_width}x#{window_height}] "</pre></dd>
  3329. <dt>NEW_SESSION_TEMPLATE</dt>
  3330. <dd><pre>"#{session_name}:"</pre></dd>
  3331. <dt>BREAK_PANE_TEMPLATE</dt>
  3332. <dd><pre>"#{session_name}:#{window_index}.#{pane_index}"</pre></dd>
  3333. <dt>NEW_WINDOW_TEMPLATE</dt>
  3334. <dd><pre>"#{session_name}:#{window_index}.#{pane_index}"</pre></dd>
  3335. <dt>SPLIT_WINDOW_TEMPLATE</dt>
  3336. <dd><pre>"#{session_name}:#{window_index}.#{pane_index}"</pre></dd>
  3337. </dl>
  3338.  
  3339.  
  3340.  
  3341.  
  3342.  
  3343. <h2>tmux main() processing order:</h2>
  3344. <pre class="prettyprint lang-config">
  3345. struct options   global_options;  /* server options */
  3346. struct options   global_s_options;  /* session options */
  3347. struct options   global_w_options;  /* window options */
  3348. struct environ   global_environ;
  3349. </pre>
  3350.  
  3351. <ol>
  3352. <li>Parse cmd line options <code>while ((opt = getopt(argc, argv, "2c:Cdf:lL:qS:uUVv")) != -1)</code></li>
  3353. <li>Setup global environment <code>for (var = environ; *var != NULL; var++)  environ_put(&amp;global_environ, *var);</code></li>
  3354.  <li>Set PWD <code>if (getcwd(tmp, sizeof tmp) != NULL)  environ_set(&amp;global_environ, "PWD", tmp);</code></li>
  3355. <li>Populate Server Options <code>options_table_populate_tree(server_options_table, &amp;global_options)</code></li>
  3356. <li>Populate Session Options <code>options_table_populate_tree(session_options_table, &amp;global_s_options);</code></li>
  3357.  <li>Set default-shell in global session option to the current shell <code>options_set_string(&amp;global_s_options, "default-shell", "%s", getshell());</code></li>
  3358. <li>Populate Window Options <code>options_table_populate_tree(window_options_table, &amp;global_w_options);</code></li>
  3359. <li>Enable UTF-8 if first client is on UTF-8 terminal<pre>if (flags &amp; CLIENT_UTF8) {
  3360.  options_set_number(&amp;global_s_options, "status-utf8", 1);
  3361.  options_set_number(&amp;global_s_options, "mouse-utf8", 1);
  3362.  options_set_number(&amp;global_w_options, "utf8", 1);
  3363. }</pre></li>
  3364. <li>Override keys to vi if VISUAL or EDITOR are set<pre>if ((s = getenv("VISUAL")) != NULL || (s = getenv("EDITOR")) != NULL) {
  3365.  if (strrchr(s, &#039;/&#039;) != NULL) s = strrchr(s, &#039;/&#039;) + 1;
  3366.  if (strstr(s, "vi") != NULL) keys = MODEKEY_VI;
  3367.  else keys = MODEKEY_EMACS;
  3368.  options_set_number(&amp;global_s_options, "status-keys", keys);
  3369.  options_set_number(&amp;global_w_options, "mode-keys", keys);
  3370. }</pre></li>
  3371. <li>Locate the configuration file.</li>
  3372. <li>Get path from environment <pre>s = getenv("TMUX");
  3373. if (s != NULL &amp;&amp; sscanf(s, "%255[^,],%lld,%d", in, &amp;pid, &amp;session) == 3) environ_path = xstrdup(in);</pre></li>
  3374. <li>Figure out the socket path and use.</li>
  3375. <li>Set process title.  <code>#ifdef HAVE_SETPROCTITLE setproctitle("%s (%s)", __progname, socket_path);</code></li>
  3376. <li>Pass control to the client<pre>ev_base = osdep_event_init();
  3377. exit(client_main(argc, argv, flags));</pre></li>
  3378. </ol>
  3379.  
  3380.  
  3381. <h2>tmux.c</h2>
  3382.  
  3383. <h3>makesocketpath</h3>
  3384. <p>makesocketpath sets the socketpath in this order.</p>
  3385. <ol>
  3386. <li>TMUX_TMPDIR</li>
  3387. <li>TMPDIR</li>
  3388. </ol>
  3389. <pre>
  3390. char *
  3391. makesocketpath(const char *label)
  3392. {
  3393.    char        base[MAXPATHLEN], realbase[MAXPATHLEN], *path, *s;
  3394.    struct stat sb;
  3395.    u_int       uid;
  3396.  
  3397.    uid = getuid();
  3398.    if ((s = getenv("TMUX_TMPDIR")) != NULL &amp;&amp; *s != &#039;\0&#039;)
  3399.        xsnprintf(base, sizeof base, "%s/", s);
  3400.    else if ((s = getenv("TMPDIR")) != NULL &amp;&amp; *s != &#039;\0&#039;)
  3401.        xsnprintf(base, sizeof base, "%s/tmux-%u", s, uid);
  3402.    else
  3403.        xsnprintf(base, sizeof base, "%s/tmux-%u", _PATH_TMP, uid);
  3404.  
  3405.    if (mkdir(base, S_IRWXU) != 0 &amp;&amp; errno != EEXIST)
  3406.        return (NULL);
  3407.  
  3408.    if (lstat(base, &amp;sb) != 0)
  3409.        return (NULL);
  3410.    if (!S_ISDIR(sb.st_mode)) {
  3411.        errno = ENOTDIR;
  3412.        return (NULL);
  3413.    }
  3414.    if (sb.st_uid != uid || (!S_ISDIR(sb.st_mode) &amp;&amp;
  3415.        sb.st_mode &amp; (S_IRWXG|S_IRWXO)) != 0) {
  3416.        errno = EACCES;
  3417.        return (NULL);
  3418.    }
  3419.  
  3420.    if (realpath(base, realbase) == NULL)
  3421.        strlcpy(realbase, base, sizeof realbase);
  3422.  
  3423.    xasprintf(&amp;path, "%s/%s", realbase, label);
  3424.    return (path);
  3425. }
  3426. </pre>
  3427.  
  3428.  
  3429. <h3>shell_exec</h3>
  3430. <pre>__dead void
  3431. shell_exec(const char *shell, const char *shellcmd)
  3432. {
  3433.    const char  *shellname, *ptr;
  3434.    char        *argv0;
  3435.  
  3436.    ptr = strrchr(shell, &#039;/&#039;);
  3437.    if (ptr != NULL &amp;&amp; *(ptr + 1) != &#039;\0&#039;)
  3438.        shellname = ptr + 1;
  3439.    else
  3440.        shellname = shell;
  3441.    if (login_shell)
  3442.        xasprintf(&amp;argv0, "-%s", shellname);
  3443.    else
  3444.        xasprintf(&amp;argv0, "%s", shellname);
  3445.    setenv("SHELL", shell, 1);
  3446.  
  3447.    setblocking(STDIN_FILENO, 1);
  3448.    setblocking(STDOUT_FILENO, 1);
  3449.    setblocking(STDERR_FILENO, 1);
  3450.    closefrom(STDERR_FILENO + 1);
  3451.  
  3452.    execl(shell, argv0, "-c", shellcmd, (char *) NULL);
  3453.    fatal("execl failed");
  3454. }
  3455. </pre>
  3456.  
  3457.  
  3458.  
  3459.  
  3460.  
  3461.  
  3462.  
  3463. <h2>tmux.h</h2>
  3464. <pre class="prettyprint lang-config">
  3465. extern struct options global_options;
  3466. extern struct options global_s_options;
  3467. extern struct options global_w_options;
  3468. extern struct environ global_environ;
  3469. </pre>
  3470.  
  3471.  
  3472. <h3>notify.c</h3>
  3473. <pre class="prettyprint lang-config">
  3474. void  notify_enable(void);
  3475. void  notify_disable(void);
  3476. void  notify_input(struct window_pane *, struct evbuffer *);
  3477. void  notify_window_layout_changed(struct window *);
  3478. void  notify_window_unlinked(struct session *, struct window *);
  3479. void  notify_window_linked(struct session *, struct window *);
  3480. void  notify_window_renamed(struct window *);
  3481. void  notify_attached_session_changed(struct client *);
  3482. void  notify_session_renamed(struct session *);
  3483. void  notify_session_created(struct session *);
  3484. void  notify_session_closed(struct session *);
  3485. </pre>
  3486.  
  3487.  
  3488. <h3>options-table.c</h3>
  3489. <pre>
  3490. extern const struct options_table_entry server_options_table[];
  3491. extern const struct options_table_entry session_options_table[];
  3492. extern const struct options_table_entry window_options_table[];
  3493. </pre>
  3494.  
  3495.  
  3496.  
  3497. <h3>Default Templates</h3>
  3498.  
  3499. <h3>key codes</h3>
  3500. <pre class="prettyprint lang-config">/* Special key codes. */
  3501. #define KEYC_NONE 0xfff
  3502. #define KEYC_BASE 0x1000
  3503.  
  3504. /* Key modifier bits. */
  3505. #define KEYC_ESCAPE 0x2000
  3506. #define KEYC_CTRL 0x4000
  3507. #define KEYC_SHIFT 0x8000
  3508. #define KEYC_PREFIX 0x10000
  3509.  
  3510. /* Mask to obtain key w/o modifiers. */
  3511. #define KEYC_MASK_MOD (KEYC_ESCAPE|KEYC_CTRL|KEYC_SHIFT|KEYC_PREFIX)
  3512. #define KEYC_MASK_KEY (~KEYC_MASK_MOD)
  3513.  
  3514. /* Other key codes. */
  3515. enum key_code {
  3516.  /* Mouse key. */
  3517.  KEYC_MOUSE = KEYC_BASE,
  3518.  
  3519.  /* Backspace key. */
  3520.  KEYC_BSPACE,
  3521.  
  3522.  /* Function keys. */
  3523.  KEYC_F1,
  3524.  KEYC_F2,
  3525.  KEYC_F3,
  3526.  KEYC_F4,
  3527.  KEYC_F5,
  3528.  KEYC_F6,
  3529.  KEYC_F7,
  3530.  KEYC_F8,
  3531.  KEYC_F9,
  3532.  KEYC_F10,
  3533.  KEYC_F11,
  3534.  KEYC_F12,
  3535.  KEYC_F13,
  3536.  KEYC_F14,
  3537.  KEYC_F15,
  3538.  KEYC_F16,
  3539.  KEYC_F17,
  3540.  KEYC_F18,
  3541.  KEYC_F19,
  3542.  KEYC_F20,
  3543.  KEYC_IC,
  3544.  KEYC_DC,
  3545.  KEYC_HOME,
  3546.  KEYC_END,
  3547.  KEYC_NPAGE,
  3548.  KEYC_PPAGE,
  3549.  KEYC_BTAB,
  3550.  
  3551.  /* Arrow keys. */
  3552.  KEYC_UP,
  3553.  KEYC_DOWN,
  3554.  KEYC_LEFT,
  3555.  KEYC_RIGHT,
  3556.  
  3557.  /* Numeric keypad. */
  3558.  KEYC_KP_SLASH,
  3559.  KEYC_KP_STAR,
  3560.  KEYC_KP_MINUS,
  3561.  KEYC_KP_SEVEN,
  3562.  KEYC_KP_EIGHT,
  3563.  KEYC_KP_NINE,
  3564.  KEYC_KP_PLUS,
  3565.  KEYC_KP_FOUR,
  3566.  KEYC_KP_FIVE,
  3567.  KEYC_KP_SIX,
  3568.  KEYC_KP_ONE,
  3569.  KEYC_KP_TWO,
  3570.  KEYC_KP_THREE,
  3571.  KEYC_KP_ENTER,
  3572.  KEYC_KP_ZERO,
  3573.  KEYC_KP_PERIOD,
  3574.  
  3575.  KEYC_FOCUS_IN,
  3576.  KEYC_FOCUS_OUT,
  3577. };</pre>
  3578.  
  3579. <h3>Termcap codes</h3>
  3580. <pre class="prettyprint lang-config">enum tty_code_code {
  3581.  TTYC_AX = 0,
  3582.  TTYC_ACSC,  /* acs_chars, ac */
  3583.  TTYC_BEL,  /* bell, bl */
  3584.  TTYC_BLINK,  /* enter_blink_mode, mb */
  3585.  TTYC_BOLD,  /* enter_bold_mode, md */
  3586.  TTYC_CIVIS,  /* cursor_invisible, vi */
  3587.  TTYC_CLEAR,  /* clear_screen, cl */
  3588.  TTYC_CNORM,  /* cursor_normal, ve */
  3589.  TTYC_COLORS,  /* max_colors, Co */
  3590.  TTYC_CR,  /* restore cursor colour, Cr */
  3591.  TTYC_CS,  /* set cursor colour, Cs */
  3592.  TTYC_CSR,  /* change_scroll_region, cs */
  3593.  TTYC_CUB,  /* parm_left_cursor, LE */
  3594.  TTYC_CUB1,  /* cursor_left, le */
  3595.  TTYC_CUD,  /* parm_down_cursor, DO */
  3596.  TTYC_CUD1,  /* cursor_down, do */
  3597.  TTYC_CUF,  /* parm_right_cursor, RI */
  3598.  TTYC_CUF1,  /* cursor_right, nd */
  3599.  TTYC_CUP,  /* cursor_address, cm */
  3600.  TTYC_CUU,  /* parm_up_cursor, UP */
  3601.  TTYC_CUU1,  /* cursor_up, up */
  3602.  TTYC_DCH,  /* parm_dch, DC */
  3603.  TTYC_DCH1,  /* delete_character, dc */
  3604.  TTYC_DIM,  /* enter_dim_mode, mh */
  3605.  TTYC_DL,  /* parm_delete_line, DL */
  3606.  TTYC_DL1,  /* delete_line, dl */
  3607.  TTYC_E3,
  3608.  TTYC_ECH,  /* erase_chars, ec */
  3609.  TTYC_EL,  /* clr_eol, ce */
  3610.  TTYC_EL1,  /* clr_bol, cb */
  3611.  TTYC_ENACS,  /* ena_acs, eA */
  3612.  TTYC_FSL,  /* from_status_line, fsl */
  3613.  TTYC_HOME,  /* cursor_home, ho */
  3614.  TTYC_HPA,  /* column_address, ch */
  3615.  TTYC_ICH,  /* parm_ich, IC */
  3616.  TTYC_ICH1,  /* insert_character, ic */
  3617.  TTYC_IL,  /* parm_insert_line, IL */
  3618.  TTYC_IL1,  /* insert_line, il */
  3619.  TTYC_INVIS,  /* enter_secure_mode, mk */
  3620.  TTYC_IS1,  /* init_1string, i1 */
  3621.  TTYC_IS2,  /* init_2string, i2 */
  3622.  TTYC_IS3,  /* init_3string, i3 */
  3623.  TTYC_KCBT,  /* key_btab, kB */
  3624.  TTYC_KCUB1,  /* key_left, kl */
  3625.  TTYC_KCUD1,  /* key_down, kd */
  3626.  TTYC_KCUF1,  /* key_right, kr */
  3627.  TTYC_KCUU1,  /* key_up, ku */
  3628.  TTYC_KDC2,
  3629.  TTYC_KDC3,
  3630.  TTYC_KDC4,
  3631.  TTYC_KDC5,
  3632.  TTYC_KDC6,
  3633.  TTYC_KDC7,
  3634.  TTYC_KDCH1,  /* key_dc, kD */
  3635.  TTYC_KDN2,
  3636.  TTYC_KDN3,
  3637.  TTYC_KDN4,
  3638.  TTYC_KDN5,
  3639.  TTYC_KDN6,
  3640.  TTYC_KDN7,
  3641.  TTYC_KEND,  /* key_end, ke */
  3642.  TTYC_KEND2,
  3643.  TTYC_KEND3,
  3644.  TTYC_KEND4,
  3645.  TTYC_KEND5,
  3646.  TTYC_KEND6,
  3647.  TTYC_KEND7,
  3648.  TTYC_KF1,  /* key_f1, k1 */
  3649.  TTYC_KF10,  /* key_f10, k; */
  3650.  TTYC_KF11,  /* key_f11, F1 */
  3651.  TTYC_KF12,  /* key_f12, F2 */
  3652.  TTYC_KF13,  /* key_f13, F3 */
  3653.  TTYC_KF14,  /* key_f14, F4 */
  3654.  TTYC_KF15,  /* key_f15, F5 */
  3655.  TTYC_KF16,  /* key_f16, F6 */
  3656.  TTYC_KF17,  /* key_f17, F7 */
  3657.  TTYC_KF18,  /* key_f18, F8 */
  3658.  TTYC_KF19,  /* key_f19, F9 */
  3659.  TTYC_KF2,  /* key_f2, k2 */
  3660.  TTYC_KF20,  /* key_f20, F10 */
  3661.  TTYC_KF3,  /* key_f3, k3 */
  3662.  TTYC_KF4,  /* key_f4, k4 */
  3663.  TTYC_KF5,  /* key_f5, k5 */
  3664.  TTYC_KF6,  /* key_f6, k6 */
  3665.  TTYC_KF7,  /* key_f7, k7 */
  3666.  TTYC_KF8,  /* key_f8, k8 */
  3667.  TTYC_KF9,  /* key_f9, k9 */
  3668.  TTYC_KHOM2,
  3669.  TTYC_KHOM3,
  3670.  TTYC_KHOM4,
  3671.  TTYC_KHOM5,
  3672.  TTYC_KHOM6,
  3673.  TTYC_KHOM7,
  3674.  TTYC_KHOME,  /* key_home, kh */
  3675.  TTYC_KIC2,
  3676.  TTYC_KIC3,
  3677.  TTYC_KIC4,
  3678.  TTYC_KIC5,
  3679.  TTYC_KIC6,
  3680.  TTYC_KIC7,
  3681.  TTYC_KICH1,  /* key_ic, kI */
  3682.  TTYC_KLFT2,
  3683.  TTYC_KLFT3,
  3684.  TTYC_KLFT4,
  3685.  TTYC_KLFT5,
  3686.  TTYC_KLFT6,
  3687.  TTYC_KLFT7,
  3688.  TTYC_KMOUS,  /* key_mouse, Km */
  3689.  TTYC_KNP,  /* key_npage, kN */
  3690.  TTYC_KNXT2,
  3691.  TTYC_KNXT3,
  3692.  TTYC_KNXT4,
  3693.  TTYC_KNXT5,
  3694.  TTYC_KNXT6,
  3695.  TTYC_KNXT7,
  3696.  TTYC_KPP,  /* key_ppage, kP */
  3697.  TTYC_KPRV2,
  3698.  TTYC_KPRV3,
  3699.  TTYC_KPRV4,
  3700.  TTYC_KPRV5,
  3701.  TTYC_KPRV6,
  3702.  TTYC_KPRV7,
  3703.  TTYC_KRIT2,
  3704.  TTYC_KRIT3,
  3705.  TTYC_KRIT4,
  3706.  TTYC_KRIT5,
  3707.  TTYC_KRIT6,
  3708.  TTYC_KRIT7,
  3709.  TTYC_KUP2,
  3710.  TTYC_KUP3,
  3711.  TTYC_KUP4,
  3712.  TTYC_KUP5,
  3713.  TTYC_KUP6,
  3714.  TTYC_KUP7,
  3715.  TTYC_MS,  /* modify xterm(1) selection */
  3716.  TTYC_OP,  /* orig_pair, op */
  3717.  TTYC_REV,  /* enter_reverse_mode, mr */
  3718.  TTYC_RI,  /* scroll_reverse, sr */
  3719.  TTYC_RMACS,  /* exit_alt_charset_mode */
  3720.  TTYC_RMCUP,  /* exit_ca_mode, te */
  3721.  TTYC_RMKX,  /* keypad_local, ke */
  3722.  TTYC_SE,  /* reset cursor style, Se */
  3723.  TTYC_SETAB,  /* set_a_background, AB */
  3724.  TTYC_SETAF,  /* set_a_foreground, AF */
  3725.  TTYC_SGR0,  /* exit_attribute_mode, me */
  3726.  TTYC_SITM,  /* enter_italics_mode, it */
  3727.  TTYC_SMACS,  /* enter_alt_charset_mode, as */
  3728.  TTYC_SMCUP,  /* enter_ca_mode, ti */
  3729.  TTYC_SMKX,  /* keypad_xmit, ks */
  3730.  TTYC_SMSO,  /* enter_standout_mode, so */
  3731.  TTYC_SMUL,  /* enter_underline_mode, us */
  3732.  TTYC_SS,  /* set cursor style, Ss */
  3733.  TTYC_TSL,  /* to_status_line, tsl */
  3734.  TTYC_VPA,  /* row_address, cv */
  3735.  TTYC_XENL,  /* eat_newline_glitch, xn */
  3736.  TTYC_XT,  /* xterm(1)-compatible title, XT */
  3737. };
  3738. #define NTTYCODE (TTYC_XT + 1)
  3739.  
  3740. /* Termcap types. */
  3741. enum tty_code_type {
  3742.  TTYCODE_NONE = 0,
  3743.  TTYCODE_STRING,
  3744.  TTYCODE_NUMBER,
  3745.  TTYCODE_FLAG,
  3746. };</pre>
  3747.  
  3748. <h3>Message codes</h3>
  3749. <pre>enum msgtype {
  3750.  MSG_VERSION = 12,
  3751.  
  3752.  MSG_IDENTIFY_FLAGS = 100,
  3753.  MSG_IDENTIFY_TERM,
  3754.  MSG_IDENTIFY_TTYNAME,
  3755.  MSG_IDENTIFY_CWD,
  3756.  MSG_IDENTIFY_STDIN,
  3757.  MSG_IDENTIFY_ENVIRON,
  3758.  MSG_IDENTIFY_DONE,
  3759.  
  3760.  MSG_COMMAND = 200,
  3761.  MSG_DETACH,
  3762.  MSG_DETACHKILL,
  3763.  MSG_EXIT,
  3764.  MSG_EXITED,
  3765.  MSG_EXITING,
  3766.  MSG_LOCK,
  3767.  MSG_READY,
  3768.  MSG_RESIZE,
  3769.  MSG_SHELL,
  3770.  MSG_SHUTDOWN,
  3771.  MSG_STDERR,
  3772.  MSG_STDIN,
  3773.  MSG_STDOUT,
  3774.  MSG_SUSPEND,
  3775.  MSG_UNLOCK,
  3776.  MSG_WAKEUP,
  3777. };</pre>
  3778.  
  3779. <h3>Mode key commands</h3>
  3780. <pre>enum mode_key_cmd {
  3781.  MODEKEY_NONE,
  3782.  MODEKEY_OTHER,
  3783.  
  3784.  /* Editing keys. */
  3785.  MODEKEYEDIT_BACKSPACE,
  3786.  MODEKEYEDIT_CANCEL,
  3787.  MODEKEYEDIT_COMPLETE,
  3788.  MODEKEYEDIT_CURSORLEFT,
  3789.  MODEKEYEDIT_CURSORRIGHT,
  3790.  MODEKEYEDIT_DELETE,
  3791.  MODEKEYEDIT_DELETELINE,
  3792.  MODEKEYEDIT_DELETETOENDOFLINE,
  3793.  MODEKEYEDIT_DELETEWORD,
  3794.  MODEKEYEDIT_ENDOFLINE,
  3795.  MODEKEYEDIT_ENTER,
  3796.  MODEKEYEDIT_HISTORYDOWN,
  3797.  MODEKEYEDIT_HISTORYUP,
  3798.  MODEKEYEDIT_NEXTSPACE,
  3799.  MODEKEYEDIT_NEXTSPACEEND,
  3800.  MODEKEYEDIT_NEXTWORD,
  3801.  MODEKEYEDIT_NEXTWORDEND,
  3802.  MODEKEYEDIT_PASTE,
  3803.  MODEKEYEDIT_PREVIOUSSPACE,
  3804.  MODEKEYEDIT_PREVIOUSWORD,
  3805.  MODEKEYEDIT_STARTOFLINE,
  3806.  MODEKEYEDIT_SWITCHMODE,
  3807.  MODEKEYEDIT_SWITCHMODEAPPEND,
  3808.  MODEKEYEDIT_SWITCHMODEAPPENDLINE,
  3809.  MODEKEYEDIT_SWITCHMODEBEGINLINE,
  3810.  MODEKEYEDIT_SWITCHMODECHANGELINE,
  3811.  MODEKEYEDIT_SWITCHMODESUBSTITUTE,
  3812.  MODEKEYEDIT_SWITCHMODESUBSTITUTELINE,
  3813.  MODEKEYEDIT_TRANSPOSECHARS,
  3814.  
  3815.  /* Menu (choice) keys. */
  3816.  MODEKEYCHOICE_BACKSPACE,
  3817.  MODEKEYCHOICE_BOTTOMLINE,
  3818.  MODEKEYCHOICE_CANCEL,
  3819.  MODEKEYCHOICE_CHOOSE,
  3820.  MODEKEYCHOICE_DOWN,
  3821.  MODEKEYCHOICE_ENDOFLIST,
  3822.  MODEKEYCHOICE_PAGEDOWN,
  3823.  MODEKEYCHOICE_PAGEUP,
  3824.  MODEKEYCHOICE_SCROLLDOWN,
  3825.  MODEKEYCHOICE_SCROLLUP,
  3826.  MODEKEYCHOICE_STARTNUMBERPREFIX,
  3827.  MODEKEYCHOICE_STARTOFLIST,
  3828.  MODEKEYCHOICE_TOPLINE,
  3829.  MODEKEYCHOICE_TREE_COLLAPSE,
  3830.  MODEKEYCHOICE_TREE_COLLAPSE_ALL,
  3831.  MODEKEYCHOICE_TREE_EXPAND,
  3832.  MODEKEYCHOICE_TREE_EXPAND_ALL,
  3833.  MODEKEYCHOICE_TREE_TOGGLE,
  3834.  MODEKEYCHOICE_UP,
  3835.  
  3836.  /* Copy keys. */
  3837.  MODEKEYCOPY_APPENDSELECTION,
  3838.  MODEKEYCOPY_BACKTOINDENTATION,
  3839.  MODEKEYCOPY_BOTTOMLINE,
  3840.  MODEKEYCOPY_CANCEL,
  3841.  MODEKEYCOPY_CLEARSELECTION,
  3842.  MODEKEYCOPY_COPYPIPE,
  3843.  MODEKEYCOPY_COPYLINE,
  3844.  MODEKEYCOPY_COPYENDOFLINE,
  3845.  MODEKEYCOPY_COPYSELECTION,
  3846.  MODEKEYCOPY_DOWN,
  3847.  MODEKEYCOPY_ENDOFLINE,
  3848.  MODEKEYCOPY_GOTOLINE,
  3849.  MODEKEYCOPY_HALFPAGEDOWN,
  3850.  MODEKEYCOPY_HALFPAGEUP,
  3851.  MODEKEYCOPY_HISTORYBOTTOM,
  3852.  MODEKEYCOPY_HISTORYTOP,
  3853.  MODEKEYCOPY_JUMP,
  3854.  MODEKEYCOPY_JUMPAGAIN,
  3855.  MODEKEYCOPY_JUMPREVERSE,
  3856.  MODEKEYCOPY_JUMPBACK,
  3857.  MODEKEYCOPY_JUMPTO,
  3858.  MODEKEYCOPY_JUMPTOBACK,
  3859.  MODEKEYCOPY_LEFT,
  3860.  MODEKEYCOPY_MIDDLELINE,
  3861.  MODEKEYCOPY_NEXTPAGE,
  3862.  MODEKEYCOPY_NEXTSPACE,
  3863.  MODEKEYCOPY_NEXTSPACEEND,
  3864.  MODEKEYCOPY_NEXTWORD,
  3865.  MODEKEYCOPY_NEXTWORDEND,
  3866.  MODEKEYCOPY_OTHEREND,
  3867.  MODEKEYCOPY_PREVIOUSPAGE,
  3868.  MODEKEYCOPY_PREVIOUSSPACE,
  3869.  MODEKEYCOPY_PREVIOUSWORD,
  3870.  MODEKEYCOPY_RECTANGLETOGGLE,
  3871.  MODEKEYCOPY_RIGHT,
  3872.  MODEKEYCOPY_SCROLLDOWN,
  3873.  MODEKEYCOPY_SCROLLUP,
  3874.  MODEKEYCOPY_SEARCHAGAIN,
  3875.  MODEKEYCOPY_SEARCHDOWN,
  3876.  MODEKEYCOPY_SEARCHREVERSE,
  3877.  MODEKEYCOPY_SEARCHUP,
  3878.  MODEKEYCOPY_SELECTLINE,
  3879.  MODEKEYCOPY_STARTNUMBERPREFIX,
  3880.  MODEKEYCOPY_STARTOFLINE,
  3881.  MODEKEYCOPY_STARTSELECTION,
  3882.  MODEKEYCOPY_TOPLINE,
  3883.  MODEKEYCOPY_UP,
  3884. };</pre>
  3885.  
  3886. <h3>Modes</h3>
  3887. <pre class="prettyprint lang-config">#define MODE_CURSOR 0x1
  3888. #define MODE_INSERT 0x2
  3889. #define MODE_KCURSOR 0x4
  3890. #define MODE_KKEYPAD 0x8  /* set = application, clear = number */
  3891. #define MODE_WRAP 0x10    /* whether lines wrap */
  3892. #define MODE_MOUSE_STANDARD 0x20
  3893. #define MODE_MOUSE_BUTTON 0x40
  3894. #define MODE_MOUSE_ANY 0x80
  3895. #define MODE_MOUSE_UTF8 0x100
  3896. #define MODE_MOUSE_SGR 0x200
  3897. #define MODE_BRACKETPASTE 0x400
  3898. #define MODE_FOCUSON 0x800
  3899.  
  3900. #define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ANY)</pre>
  3901.  
  3902.  
  3903. <h3>Grid attributes</h3>
  3904. <pre class="prettyprint lang-config">#define GRID_ATTR_BRIGHT 0x1
  3905. #define GRID_ATTR_DIM 0x2
  3906. #define GRID_ATTR_UNDERSCORE 0x4
  3907. #define GRID_ATTR_BLINK 0x8
  3908. #define GRID_ATTR_REVERSE 0x10
  3909. #define GRID_ATTR_HIDDEN 0x20
  3910. #define GRID_ATTR_ITALICS 0x40
  3911. #define GRID_ATTR_CHARSET 0x80  /* alternative character set */</pre>
  3912.  
  3913. <h3>Layout direction</h3>
  3914. <pre>enum layout_type {
  3915.  LAYOUT_LEFTRIGHT,
  3916.  LAYOUT_TOPBOTTOM,
  3917.  LAYOUT_WINDOWPANE
  3918. };</pre>
  3919.  
  3920.  
  3921. <h3>Mouse</h3>
  3922. <pre class="prettyprint lang-config">
  3923. /* Mouse button masks. */
  3924. #define MOUSE_MASK_BUTTONS 3
  3925. #define MOUSE_MASK_SHIFT 4
  3926. #define MOUSE_MASK_META 8
  3927. #define MOUSE_MASK_CTRL 16
  3928. #define MOUSE_MASK_DRAG 32
  3929. #define MOUSE_MASK_WHEEL 64
  3930.  
  3931. /* Mouse wheel states. */
  3932. #define MOUSE_WHEEL_UP 0
  3933. #define MOUSE_WHEEL_DOWN 1
  3934.  
  3935. /* Mouse event bits. */
  3936. #define MOUSE_EVENT_DOWN 0x1
  3937. #define MOUSE_EVENT_DRAG 0x2
  3938. #define MOUSE_EVENT_UP 0x4
  3939. #define MOUSE_EVENT_CLICK 0x8
  3940. #define MOUSE_EVENT_WHEEL 0x10
  3941.  
  3942. /* Mouse flag bits. */
  3943. #define MOUSE_RESIZE_PANE 0x1
  3944. </pre>
  3945.  
  3946.  
  3947. <h3>Option table entries</h3>
  3948. <pre class="prettyprint lang-config">
  3949. /*
  3950. * Option table entries. The option table is the user-visible part of the
  3951. * option, as opposed to the internal options (struct option) which are just
  3952. * number or string.
  3953. */
  3954. enum options_table_type {
  3955.    OPTIONS_TABLE_STRING,
  3956.    OPTIONS_TABLE_NUMBER,
  3957.    OPTIONS_TABLE_KEY,
  3958.    OPTIONS_TABLE_COLOUR,
  3959.    OPTIONS_TABLE_ATTRIBUTES,
  3960.    OPTIONS_TABLE_FLAG,
  3961.    OPTIONS_TABLE_CHOICE,
  3962.    OPTIONS_TABLE_STYLE
  3963. };
  3964. </pre>
  3965.  
  3966.  
  3967. <h3>Common command usages</h3>
  3968. <pre class="prettyprint lang-config">
  3969. /* Common command usages. */
  3970. #define CMD_TARGET_PANE_USAGE "[-t target-pane]"
  3971. #define CMD_TARGET_WINDOW_USAGE "[-t target-window]"
  3972. #define CMD_TARGET_SESSION_USAGE "[-t target-session]"
  3973. #define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
  3974. #define CMD_SRCDST_PANE_USAGE "[-s src-pane] [-t dst-pane]"
  3975. #define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]"
  3976. #define CMD_SRCDST_SESSION_USAGE "[-s src-session] [-t dst-session]"
  3977. #define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
  3978. #define CMD_BUFFER_USAGE "[-b buffer-index]"
  3979. </pre>
  3980.  
  3981.  
  3982.  
  3983. <h2>colour.c</h2>
  3984. <p>Colour to string conversion functions. Bit 8 of the colour means it is one of the 256 colour palette.</p>
  3985. <pre>
  3986. /* An RGB colour. */
  3987. struct colour_rgb {
  3988.    u_char  r;
  3989.    u_char  g;
  3990.    u_char  b;
  3991. };
  3992.  
  3993. /* 256 colour RGB table, generated on first use. */
  3994. struct colour_rgb *colour_rgb_256;
  3995.  
  3996. void    colour_rgb_generate256(void);
  3997. u_int   colour_rgb_distance(struct colour_rgb *, struct colour_rgb *);
  3998. int colour_rgb_find(struct colour_rgb *);
  3999. </pre>
  4000.  
  4001. <h3>Generate 256 colour RGB table.</h3>
  4002. <pre class="prettyprint lang-config">void
  4003. colour_rgb_generate256(void)
  4004. {
  4005.    struct colour_rgb   *rgb;
  4006.    u_int            i, r, g, b;
  4007.  
  4008.    /*
  4009.     * Allocate the table. The first 16 colours are often changed by users
  4010.     * and terminals so don&#039;t include them.
  4011.     */
  4012.    colour_rgb_256 = xcalloc(240, sizeof *colour_rgb_256);
  4013.  
  4014.    /* Add the colours first. */
  4015.    r = g = b = 0;
  4016.    for (i = 240; i &gt; 24; i--) {
  4017.        rgb = &amp;colour_rgb_256[240 - i];
  4018.  
  4019.        if (r != 0)
  4020.            rgb-&gt;r = (r * 40) + 55;
  4021.        if (g != 0)
  4022.            rgb-&gt;g = (g * 40) + 55;
  4023.        if (b != 0)
  4024.            rgb-&gt;b = (b * 40) + 55;
  4025.  
  4026.        b++;
  4027.        if (b &gt; 5) {
  4028.            b = 0;
  4029.            g++;
  4030.        }
  4031.        if (g &gt; 5) {
  4032.            g = 0;
  4033.            r++;
  4034.        }
  4035.    }
  4036.  
  4037.    /* Then add the greys. */
  4038.    for (i = 24; i &gt; 0; i--) {
  4039.        rgb = &amp;colour_rgb_256[240 - i];
  4040.  
  4041.        rgb-&gt;r = 8 + (24 - i) * 10;
  4042.        rgb-&gt;g = 8 + (24 - i) * 10;
  4043.        rgb-&gt;b = 8 + (24 - i) * 10;
  4044.    }
  4045. }</pre>
  4046.  
  4047. <h3>Get colour RGB distance.</h3>
  4048. <pre>u_int
  4049. colour_rgb_distance(struct colour_rgb *rgb1, struct colour_rgb *rgb2)
  4050. {
  4051.    int r, g, b;
  4052.  
  4053.    r = rgb1-&gt;r - rgb2-&gt;r;
  4054.    g = rgb1-&gt;g - rgb2-&gt;g;
  4055.    b = rgb1-&gt;b - rgb2-&gt;b;
  4056.    return (r * r + g * g + b * b);
  4057. }</pre>
  4058.  
  4059. <h3>Work out the nearest colour from the 256 colour set.</h3>
  4060. <pre>int
  4061. colour_rgb_find(struct colour_rgb *rgb)
  4062. {
  4063.    u_int   distance, lowest, colour, i;
  4064.  
  4065.    if (colour_rgb_256 == NULL)
  4066.        colour_rgb_generate256();
  4067.  
  4068.    colour = 16;
  4069.    lowest = UINT_MAX;
  4070.    for (i = 0; i &lt; 240; i++) {
  4071.        distance = colour_rgb_distance(&amp;colour_rgb_256[i], rgb);
  4072.        if (distance &lt; lowest) {
  4073.            lowest = distance;
  4074.            colour = 16 + i;
  4075.        }
  4076.    }
  4077.    return (colour);
  4078. }</pre>
  4079.  
  4080. <h3>Convert colour to a string.</h3>
  4081. <pre>
  4082. const char *
  4083. colour_tostring(int c)
  4084. {
  4085.    static char s[32];
  4086.  
  4087.    if (c &amp; 0x100) {
  4088.        xsnprintf(s, sizeof s, "colour%u", c &amp; ~0x100);
  4089.        return (s);
  4090.    }
  4091.  
  4092.    switch (c) {
  4093.    case 0:
  4094.        return ("black");
  4095.    case 1:
  4096.        return ("red");
  4097.    case 2:
  4098.        return ("green");
  4099.    case 3:
  4100.        return ("yellow");
  4101.    case 4:
  4102.        return ("blue");
  4103.    case 5:
  4104.        return ("magenta");
  4105.    case 6:
  4106.        return ("cyan");
  4107.    case 7:
  4108.        return ("white");
  4109.    case 8:
  4110.        return ("default");
  4111.    case 90:
  4112.        return ("brightblack");
  4113.    case 91:
  4114.        return ("brightred");
  4115.    case 92:
  4116.        return ("brightgreen");
  4117.    case 93:
  4118.        return ("brightyellow");
  4119.    case 94:
  4120.        return ("brightblue");
  4121.    case 95:
  4122.        return ("brightmagenta");
  4123.    case 96:
  4124.        return ("brightcyan");
  4125.    case 97:
  4126.        return ("brightwhite");
  4127.    }
  4128.    return (NULL);
  4129. }</pre>
  4130.  
  4131.  
  4132. <h3>Convert colour from string.</h3>
  4133. <pre>
  4134. int
  4135. colour_fromstring(const char *s)
  4136. {
  4137.    const char      *errstr;
  4138.    const char      *cp;
  4139.    struct colour_rgb    rgb;
  4140.    int          n;
  4141.  
  4142.    if (*s == &#039;#&#039; &amp;&amp; strlen(s) == 7) {
  4143.        for (cp = s + 1; isxdigit((u_char) *cp); cp++)
  4144.            ;
  4145.        if (*cp != &#039;\0&#039;)
  4146.            return (-1);
  4147.        n = sscanf(s + 1, "%2hhx%2hhx%2hhx", &amp;rgb.r, &amp;rgb.g, &amp;rgb.b);
  4148.        if (n != 3)
  4149.            return (-1);
  4150.        return (colour_rgb_find(&amp;rgb) | 0x100);
  4151.    }
  4152.  
  4153.    if (strncasecmp(s, "colour", (sizeof "colour") - 1) == 0) {
  4154.        n = strtonum(s + (sizeof "colour") - 1, 0, 255, &amp;errstr);
  4155.        if (errstr != NULL)
  4156.            return (-1);
  4157.        return (n | 0x100);
  4158.    }
  4159.  
  4160.    if (strcasecmp(s, "black") == 0 || (s[0] == &#039;0&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4161.        return (0);
  4162.    if (strcasecmp(s, "red") == 0 || (s[0] == &#039;1&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4163.        return (1);
  4164.    if (strcasecmp(s, "green") == 0 || (s[0] == &#039;2&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4165.        return (2);
  4166.    if (strcasecmp(s, "yellow") == 0 || (s[0] == &#039;3&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4167.        return (3);
  4168.    if (strcasecmp(s, "blue") == 0 || (s[0] == &#039;4&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4169.        return (4);
  4170.    if (strcasecmp(s, "magenta") == 0 || (s[0] == &#039;5&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4171.        return (5);
  4172.    if (strcasecmp(s, "cyan") == 0 || (s[0] == &#039;6&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4173.        return (6);
  4174.    if (strcasecmp(s, "white") == 0 || (s[0] == &#039;7&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4175.        return (7);
  4176.    if (strcasecmp(s, "default") == 0 || (s[0] == &#039;8&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4177.        return (8);
  4178.    if (strcasecmp(s, "brightblack") == 0 ||
  4179.        (s[0] == &#039;9&#039; &amp;&amp; s[1] == &#039;0&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4180.        return (90);
  4181.    if (strcasecmp(s, "brightred") == 0 ||
  4182.        (s[0] == &#039;9&#039; &amp;&amp; s[1] == &#039;1&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4183.        return (91);
  4184.    if (strcasecmp(s, "brightgreen") == 0 ||
  4185.        (s[0] == &#039;9&#039; &amp;&amp; s[1] == &#039;2&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4186.        return (92);
  4187.    if (strcasecmp(s, "brightyellow") == 0 ||
  4188.        (s[0] == &#039;9&#039; &amp;&amp; s[1] == &#039;3&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4189.        return (93);
  4190.    if (strcasecmp(s, "brightblue") == 0 ||
  4191.        (s[0] == &#039;9&#039; &amp;&amp; s[1] == &#039;4&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4192.        return (94);
  4193.    if (strcasecmp(s, "brightmagenta") == 0 ||
  4194.        (s[0] == &#039;9&#039; &amp;&amp; s[1] == &#039;5&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4195.        return (95);
  4196.    if (strcasecmp(s, "brightcyan") == 0 ||
  4197.        (s[0] == &#039;9&#039; &amp;&amp; s[1] == &#039;6&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4198.        return (96);
  4199.    if (strcasecmp(s, "brightwhite") == 0 ||
  4200.        (s[0] == &#039;9&#039; &amp;&amp; s[1] == &#039;7&#039; &amp;&amp; s[1] == &#039;\0&#039;))
  4201.        return (97);
  4202.    return (-1);
  4203. }
  4204. </pre>
  4205.  
  4206.  
  4207.  
  4208.  
  4209. <h3>Convert 256 colour palette to 16.</h3>
  4210. <pre>
  4211. u_char
  4212. colour_256to16(u_char c)
  4213. {
  4214.    static const u_char table[256] = {
  4215.         0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
  4216.         0,  4,  4,  4, 12, 12,  2,  6,  4,  4, 12, 12,  2,  2,  6,  4,
  4217.        12, 12,  2,  2,  2,  6, 12, 12, 10, 10, 10, 10, 14, 12, 10, 10,
  4218.        10, 10, 10, 14,  1,  5,  4,  4, 12, 12,  3,  8,  4,  4, 12, 12,
  4219.         2,  2,  6,  4, 12, 12,  2,  2,  2,  6, 12, 12, 10, 10, 10, 10,
  4220.        14, 12, 10, 10, 10, 10, 10, 14,  1,  1,  5,  4, 12, 12,  1,  1,
  4221.         5,  4, 12, 12,  3,  3,  8,  4, 12, 12,  2,  2,  2,  6, 12, 12,
  4222.        10, 10, 10, 10, 14, 12, 10, 10, 10, 10, 10, 14,  1,  1,  1,  5,
  4223.        12, 12,  1,  1,  1,  5, 12, 12,  1,  1,  1,  5, 12, 12,  3,  3,
  4224.         3,  7, 12, 12, 10, 10, 10, 10, 14, 12, 10, 10, 10, 10, 10, 14,
  4225.         9,  9,  9,  9, 13, 12,  9,  9,  9,  9, 13, 12,  9,  9,  9,  9,
  4226.        13, 12,  9,  9,  9,  9, 13, 12, 11, 11, 11, 11,  7, 12, 10, 10,
  4227.        10, 10, 10, 14,  9,  9,  9,  9,  9, 13,  9,  9,  9,  9,  9, 13,
  4228.         9,  9,  9,  9,  9, 13,  9,  9,  9,  9,  9, 13,  9,  9,  9,  9,
  4229.         9, 13, 11, 11, 11, 11, 11, 15,  0,  0,  0,  0,  0,  0,  8,  8,
  4230.         8,  8,  8,  8,  7,  7,  7,  7,  7,  7, 15, 15, 15, 15, 15, 15
  4231.    };
  4232.  
  4233.    return (table[c]);
  4234. }
  4235.  
  4236.  
  4237.  
  4238.  
  4239.  
  4240.  
  4241.  
  4242.  
  4243.  
  4244.  
  4245.  
  4246.  
  4247.  
  4248.  
  4249.  
  4250.  
  4251.  
  4252.  
  4253.  
  4254.  
  4255. <h2>More Reading</h2>
  4256. <ol>
  4257. <li><a href="http://tmux.svn.sourceforge.net/viewvc/tmux/trunk/FAQ" title="TMUX FAQ - Trunk">TMUX FAQ - Trunk</a></li>
  4258. <li><a href="http://tmux.svn.sourceforge.net/viewvc/tmux/trunk/examples/">TMUX Examples</a> </li>
  4259. <li><a href="https://wiki.archlinux.org/index.php/Tmux">https://wiki.archlinux.org/index.php/Tmux</a></li>
  4260. <li><a href="http://mutelight.org/articles/practical-tmux" title="Practical Tmux">http://mutelight.org/articles/practical-tmux</a></li>
  4261. <li><a href="https://www.askapache.com/linux/zen-terminal-escape-codes/">Terminal ZEN</a></li>
  4262. </ol>
  4263.  
  4264. <h3>JWR</h3>
  4265. <ol>
  4266. <li><a href="http://jasonwryan.com/post/6279048610/tmux-copy">Copy and Paste</a></li>
  4267. <li><a href="http://jasonwryan.com/post/320721668/tmux-terminal-multiplexer">tmux multiplexer</a></li>
  4268. <li><a href="http://jasonwryan.com/post/1233829137/tmux-sessions">tmux sessions</a></li>
  4269. </ol>
  4270.  
  4271. <h3>tmux.conf examples</h3>
  4272. <ol>
  4273. <li><a href="https://bitbucket.org/jasonwryan/eeepc/src/55c635aab7a4/.tmux/conf">jasonwryan tmux.conf</a></li>
  4274. </ol>
  4275.  
  4276. <h3>URXVT</h3>
  4277. <ol>
  4278. <li><a href="http://linux.die.net/man/7/urxvt" title="URXVT Man Page">http://linux.die.net/man/7/urxvt</a></li>
  4279. </ol><p><a rel="nofollow" href="https://www.askapache.com/hacking/tmux/">TMUX</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4280. ]]></content:encoded>
  4281. <wfw:commentRss>https://www.askapache.com/hacking/tmux/feed/</wfw:commentRss>
  4282. <slash:comments>0</slash:comments>
  4283. </item>
  4284. <item>
  4285. <title>Caching WordPress with Batcache and Memcache</title>
  4286. <link>https://www.askapache.com/wordpress/caching-wordpress-batcache-memcache/</link>
  4287. <comments>https://www.askapache.com/wordpress/caching-wordpress-batcache-memcache/#respond</comments>
  4288. <pubDate>Sat, 16 Jul 2016 20:02:43 +0000</pubDate>
  4289. <dc:creator><![CDATA[AskApache]]></dc:creator>
  4290. <category><![CDATA[Optimization]]></category>
  4291. <category><![CDATA[WordPress]]></category>
  4292. <category><![CDATA[Cache]]></category>
  4293. <category><![CDATA[Load]]></category>
  4294. <category><![CDATA[memcache]]></category>
  4295. <category><![CDATA[memcached]]></category>
  4296. <category><![CDATA[performance]]></category>
  4297. <category><![CDATA[server]]></category>
  4298. <category><![CDATA[speed]]></category>
  4299.  
  4300. <guid isPermaLink="false">https://www.askapache.com/?p=9725</guid>
  4301. <description><![CDATA[<p><a class="IFL" href="https://www.askapache.com/wordpress/caching-wordpress-batcache-memcache/"><img src="https://www.askapache.com/s/u.askapache.com/2016/07/join-me.jpg" alt="join-me" width="220" height="294" /></a>Using memcache for me personally and the client sites I work on, has improved performance by over 1000%, in some cases even higher than that.  It is a truly revolutionary way to optimize the performance of MySQL queries, remote requests such as to twitter or other apis, and this article is step 1.  Plan is to go all the way to step 10 in future articles, it it grossly underused and misused in the WP world.<br class="C" /></p>
  4302. <p><a rel="nofollow" href="https://www.askapache.com/wordpress/caching-wordpress-batcache-memcache/">Caching WordPress with Batcache and Memcache</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4303. ]]></description>
  4304. <content:encoded><![CDATA[<h2>What memcache Does</h2>
  4305. <div><img src="https://www.askapache.com/s/u.askapache.com/2015/09/memcached-usage.png" alt="memcached-usage" width="251" height="468" class="IFR" />
  4306. <p>memcached is a high-performance, distributed memory object caching system, generic in nature, but originally intended for use in speeding up dynamic web applications by alleviating database load.</p>
  4307. <p>You can think of it as a short-term memory for your applications.</p>
  4308. <p>memcached allows you to take memory from parts of your system where you have more than you need and make it accessible to areas where you have less than you need.</p>
  4309. <p>memcached also allows you to make better use of your memory.  If you consider the diagram to the right, you can see two deployment scenarios:</p>
  4310. <ol><li>Each node is completely independent (top).</li><li>Each node can make use of memory from other nodes (bottom).</li></ol>
  4311. <p>The first scenario illustrates the classic deployment strategy, however you'll find that it's both wasteful in the sense that the total cache size is a fraction of the actual capacity of your web farm, but also in the amount of effort required to keep the cache consistent across all of those nodes.<p>
  4312. <p>With memcached, you can see that all of the servers are looking into the same virtual pool of memory.  This means that a given item is always stored and always retrieved from the same location in your entire web cluster.</p>
  4313. <p>Also, as the demand for your application grows to the point where you need to have more servers, it generally also grows in terms of the data that must be regularly accessed.  A deployment strategy where these two aspects of your system scale together just makes sense.</p>
  4314. <p>The illustration to the right only shows two web servers for simplicity, but the property remains the same as the number increases.  If you had fifty web servers, you'd still have a usable cache size of 64MB in the first example, but in the second, you'd have 3.2GB of usable cache.</p>
  4315. <p>Of course, you aren't required to use your web server's memory for cache.  Many memcached users have dedicated machines that are built to only be memcached servers.</p><br class="C" /></div>
  4316.  
  4317. <h2>Setup WordPress Caching for Memcache</h2>
  4318. <ol>
  4319. <li>Install <a href="http://memcached.org/">memcached</a></li>
  4320. <li>Install the <a href="http://pecl.php.net/package/memcache">PECL memcached extension</a>.</li>
  4321. <li>Install the <a href="http://wordpress.org/extend/plugins/batcache/">Batcache Manager plugin</a>.</li>
  4322. <li>Install the <a href="https://wordpress.org/plugins/memcached/">Memcached Redux plugin</a>.</li>
  4323. </ol>
  4324.  
  4325. <h3>Batcache Manager Plugin</h3>
  4326. <p>Install the <a href="http://wordpress.org/extend/plugins/batcache/">Batcache Manager plugin</a>.</p>
  4327. <blockquote>
  4328. <p>Batcache uses Memcached to store and serve rendered pages. It can also optionally cache redirects. It's not as fast as Donncha's WP-Super-Cache but it can be used where file-based caching is not practical or not desired. For instance, any site that is run on more than one server should use Batcache because it allows all servers to use the same storage.</p>
  4329. <p>Development testing showed a 40x reduction in page generation times: pages generated in 200ms were served from the cache in 5ms. Traffic simulations with Siege demonstrate that WordPress can handle up to twenty times more traffic with Batcache installed.</p>
  4330. <p>Batcache is aimed at preventing a flood of traffic from breaking your site. It does this by serving old pages to new users. This reduces the demand on the web server CPU and the database. It also means some people may see a page that is a few minutes old. However this only applies to people who have not interacted with your web site before. Once they have logged in or left a comment they will always get fresh pages.</p>
  4331. </blockquote>
  4332.  
  4333. <h3>Memcached Redux</h3>
  4334. <p>Install the <a href="https://wordpress.org/plugins/memcached/">Memcached Redux plugin</a>.</p>
  4335. <blockquote cite="https://wordpress.org/plugins/memcached/"><p>Memcached Object Cache provides a persistent backend for the WordPress object cache. A memcached server and the PECL memcache extension are required.</p></blockquote>
  4336.  
  4337. <h3>memcached PECL extension</h3>
  4338. <p>Install the <a href="http://pecl.php.net/package/memcache">PECL memcached extension</a>.</p>
  4339. <blockquote cite="http://pecl.php.net/package/memcache">Memcached is a caching daemon designed especially for dynamic web applications to decrease database load by storing objects in memory.
  4340. This extension allows you to work with memcached through handy OO and procedural interfaces.</blockquote>
  4341.  
  4342. <h3>Memcached</h3>
  4343. <h4>CentOS / RedHat</h4>
  4344. <p>Yum packages needed: <code>yum install libmemcached memcached memcached-devel php56u-pecl-memcache php56u-pecl-memcached</code></p>
  4345.  
  4346. <h4>ArchLinux</h4>
  4347. <p>Pacman packages needed: <code>pacman -S memcached php-memcache libmemcached</code></p>
  4348.  
  4349.  
  4350.  
  4351.  
  4352.  
  4353.  
  4354. <h2>phpMemcachedAdmin</h2>
  4355. <p>Install <a href="https://code.google.com/p/phpmemcacheadmin/">phpMemcachedAdmin from its google code page</a>.</p>
  4356. <p><img src="https://www.askapache.com/s/u.askapache.com/2015/09/phpmemcached.png" alt="phpmemcached" width="909" height="835" class="alignnone size-full wp-image-9738" /></p>
  4357. <blockquote cite="https://code.google.com/p/phpmemcacheadmin/"><p>Graphic stand-alone administration for memcached to monitor and debug purpose</p>
  4358. <p>This program allows to see in real-time (top-like) or from the start of the server, stats for get, set, delete, increment, decrement, evictions, reclaimed, cas command, as well as server stats (network, items, server version) with googlecharts and server internal configuration</p>
  4359. <p>You can go further to see each server slabs, occupation, memory wasted and items (key & value).</p>
  4360. <p>Another part can execute commands to any memcached server : get, set, delete, flush_all, as well as execute any commands (like stats) with telnet</p>
  4361. <p>To extract these informations, phpMemcacheAdmin uses, as you wish, direct communication with server, PECL Memcache or PECL Memcached API.</p></blockquote>
  4362.  
  4363.  
  4364. <h2>Memcache Tips and Tricks</h2>
  4365. <p>Stay tuned for my next memcache article.  It will consist entirely of practical uses or memcache and how to best utilize the power of this amazing tool for WordPress.  Much of my initial learning and experience with this comes from my background working for WordPress VIP.</p>
  4366.  
  4367. <p><a rel="nofollow" href="https://www.askapache.com/wordpress/caching-wordpress-batcache-memcache/">Caching WordPress with Batcache and Memcache</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4368. ]]></content:encoded>
  4369. <wfw:commentRss>https://www.askapache.com/wordpress/caching-wordpress-batcache-memcache/feed/</wfw:commentRss>
  4370. <slash:comments>0</slash:comments>
  4371. </item>
  4372. <item>
  4373. <title>I got hacked</title>
  4374. <link>https://www.askapache.com/hacking/i-got-hacked/</link>
  4375. <comments>https://www.askapache.com/hacking/i-got-hacked/#respond</comments>
  4376. <pubDate>Fri, 24 Jun 2016 01:05:08 +0000</pubDate>
  4377. <dc:creator><![CDATA[AskApache]]></dc:creator>
  4378. <category><![CDATA[Hacking]]></category>
  4379. <category><![CDATA[hack]]></category>
  4380. <category><![CDATA[hacked]]></category>
  4381. <category><![CDATA[p0wned]]></category>
  4382.  
  4383. <guid isPermaLink="false">https://www.askapache.com/?p=9823</guid>
  4384. <description><![CDATA[<p><a href="https://www.askapache.com/hacking/i-got-hacked/" class="IFL"><img src="https://www.askapache.com/s/u.askapache.com/2016/06/p0wned-300x199.jpg" alt="p0wned" width="300" height="199" /></a>Well, not this sites server, which has never been hacked, but a server hosted with hostgator.</p>
  4385. <p>Interestingly, the hacker sent me an email and left me an mp3, which I've uploaded for your listening leisure.</p>
  4386. <p>Do real hackers exist? Yes.  Can we coexist?  Preferably!<br class="C" /></p>
  4387. <p><a rel="nofollow" href="https://www.askapache.com/hacking/i-got-hacked/">I got hacked</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4388. ]]></description>
  4389. <content:encoded><![CDATA[Well, not this sites server, which has never been hacked (not because it's running a secured OpenBSD stack but because it's a small target and why hack a hacker), but a server hosted with hostgator.  I've used hostgator for about 8 years now as they are very cheap pricing for very large disk space, not the best bandwidth but good cpanel-free linux hosting. I highly recommend them for sites where processing speed isn't as important (which it is on WordPress sites) and where large disk space and long-term stability is important. <em>Aside: I will never ever ever recommend using <a href="https://www.askapache.com/hacking/uninstall-cpanel/">cpanel</a>.</em>
  4390.  
  4391. <h2>Got P0wned</h2>
  4392. <p><img src="https://www.askapache.com/s/u.askapache.com/2016/06/p0wned-300x199.jpg" alt="hacked" width="300" height="199" class="IFL" />The interesting thing is the one who achieved access via some clever php exploitation of some outdated php scripts I had left up was someone who values knowledge and hacking for the hack value over childish vandalism of technology.  I'm not denigrating political hacktivism, I'm all for that, just saying this wasn't an exploit malware farm bot but an actual humanoid.<br /><br />I know because of how I became aware of the hack, I received an email using PGP from the security researcher who detailed the vulnerabilities exploited and also left an mp3 file in my root directory.  They were anonymized fairly well, but I didn't want to pursue that angle at all due to the polite nature of this user.<br /><br />I'm all for getting hacked like this, and hacking like this, as much as possible, it may appear on the surface to be a pain, but the net result of this attack is just that my server is now locked down to prevent that specific type of attack from happening again.<br class="C" /></p>
  4393.  
  4394. <h2>MP3 left in root</h2>
  4395. <p>This hacker left an audio file in my root directory to prove that they attained full 100% ownership and control of my system.  They had gained root access after elevating from the initial hack and then used ssh authorized keys to attain full console access without needing the password.  It was a nice way to do that, and I enjoyed the unusual act of leaving an mp3 which I don't see often. Much nicer than those stupid txt files that malware bots have been leaving around as much as possible lately, plain text files that contain stupid text like "pro-isis hackers have owned your box" and also "anti-isis hackers have owned your box".. and french hackers, russian hackers, iran hackers, blah blah so stupid.  So old-school but they don't realize its oldschool which is w (lol).<br /><br />I put that mp3 online at <a href="http://gator.askapache.com/boom2.mp3">http://gator.askapache.com/boom2.mp3</a> not sure where it is from but reminds me of the audio files commonly embedded in cracking software such as the one I grabbed out of a key cracker and put up at <a href="http://gator.askapache.com/a.mp3">http://gator.askapache.com/a.mp3</a> which is actually a very sophisticated and tiny file (I made it large by stream ripping it).</p>
  4396. <p>Oh and don't worry about analyzing the boom mp3, I re-encoded it after ripping from a raw stream, so it's not the actual file left in my root.</p>
  4397.  
  4398. <h2>All Good</h2>
  4399. Hacking should be like this.  Respect for the technology and respect for the team.  It's unlikely that one of my servers will be hacked by some autobot exploit farm, but of course its very likely that a dedicated team or individual can hack into anything that isn't powered off.  So I'm glad that this entity had respect and didn't cause me pain :)
  4400.  
  4401. That all said, this is a rare event for me and was quite fun!  In the event of your WordPress site getting hacked, see: <a href="https://codex.wordpress.org/FAQ_My_site_was_hacked">FAQ: My site was hacked on the WordPress codex</a>.<p><a rel="nofollow" href="https://www.askapache.com/hacking/i-got-hacked/">I got hacked</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4402. ]]></content:encoded>
  4403. <wfw:commentRss>https://www.askapache.com/hacking/i-got-hacked/feed/</wfw:commentRss>
  4404. <slash:comments>0</slash:comments>
  4405. <enclosure url="http://gator.askapache.com/boom2.mp3" length="4017796" type="audio/mpeg" />
  4406. <enclosure url="http://gator.askapache.com/a.mp3" length="1913417" type="audio/mpeg" />
  4407. </item>
  4408. <item>
  4409. <title>Stopping WordPress Exploits and Spam</title>
  4410. <link>https://www.askapache.com/security/stop-wordpress-exploits-spam/</link>
  4411. <comments>https://www.askapache.com/security/stop-wordpress-exploits-spam/#respond</comments>
  4412. <pubDate>Thu, 16 Jun 2016 04:42:13 +0000</pubDate>
  4413. <dc:creator><![CDATA[AskApache]]></dc:creator>
  4414. <category><![CDATA[Hacking]]></category>
  4415. <category><![CDATA[Htaccess]]></category>
  4416. <category><![CDATA[PHP]]></category>
  4417. <category><![CDATA[Security]]></category>
  4418. <category><![CDATA[WordPress]]></category>
  4419. <category><![CDATA[security]]></category>
  4420. <category><![CDATA[spam]]></category>
  4421. <category><![CDATA[wordpress]]></category>
  4422. <category><![CDATA[wordpress exploits]]></category>
  4423.  
  4424. <guid isPermaLink="false">https://www.askapache.com/?p=9798</guid>
  4425. <description><![CDATA[<p>Secure WP Super Cache, Anti-exploits, Mitigation techniques.  A bunch of current ways to stop wordpress exploits and spam. <img style="max-width:50%" src="https://www.askapache.com/s/u.askapache.com/2016/05/0wn-wp-explits.png" alt="block the most common wordpress exploits" class="IFL" /><br class="C" /></p>
  4426. <p><a rel="nofollow" href="https://www.askapache.com/security/stop-wordpress-exploits-spam/">Stopping WordPress Exploits and Spam</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4427. ]]></description>
  4428. <content:encoded><![CDATA[<p>Here's how to block the most common wordpress exploits and spam to secure your site and server.</p>
  4429.  
  4430. <h2>Die 99% of WP Malware</h2>
  4431. <p>There are couple WP core files that you can modify to make it impossible for an attacker to exploit.  It is simply by adding a <code>die();</code> to the top of the at-risk files. <img src="https://www.askapache.com/s/u.askapache.com/2016/05/0wn-wp-explits.png" alt="0wn-wp-explits" width="1250" height="252" class="alignnone size-full wp-image-9802" /></p>
  4432. <p>Add a <code>die();</code> as the very first php line to run (after <code>&lt;?php</code>) in the following files:</p>
  4433. <ul>
  4434. <li><code>wp-links-opml.php</code></li>
  4435. <li><code>wp-comments-post.php</code></li>
  4436. <li><code>wp-trackback.php</code></li>
  4437. </ul>
  4438.  
  4439. <h3>When to die</h3>
  4440. <p><code>wp-links-opml.php</code> - can be disabled when the site is NOT using the Links feature in the backend.</p>
  4441. <p><code>wp-comments-post.php</code> - can be disabled when the site is not using WP comments, such as Disqus.</p>
  4442. <p><code>wp-trackback.php</code> - can be disabled if you aren't using trackbacks.</p>
  4443.  
  4444. <h2>Secure xmlrpc.php</h2>
  4445. <p>Unless you have a literal reason for keeping <code>xmlrpc.php</code> (such as if you rely on pings or trackbacks or 3rd-party tools for editors) this file should be blocked as it can be used for brute-force login attempts.</p>
  4446. <pre class="prettyprint lang-config">
  4447. &lt;Files xmlrpc.php&gt;
  4448. Order Deny,Allow
  4449. Deny from All
  4450. Allow from localhost
  4451. Satisfy All
  4452. &lt;/Files&gt;
  4453. </pre>
  4454.  
  4455.  
  4456.  
  4457.  
  4458.  
  4459. <h2>Block obvious Spam</h2>
  4460. <p>The best way to create targeted .htaccess rules for blocking spam is to add a logging statement to the php files like comments.php in order to see the HTTP headers and request needed for designing specific blocks against them.</p>
  4461.  
  4462. <p>Posts to <code>/wp-login.php</code> that are using HTTP Protocol version 1.0 (not 1.1) are essentially almost always spam unless your server is acting as an origin for some proxying cache like an F5, varnish, etc.</p>
  4463. <pre class="prettyprint lang-config">
  4464. RewriteCond %{THE_REQUEST} ^POST\ /wp-login.php\ HTTP/1\.0 [NC]
  4465. RewriteRule .* - [F]
  4466.  
  4467. RewriteCond %{THE_REQUEST} !^(POST|GET|HEAD|PROPFIND|OPTIONS)\ .+\ HTTP/(0\.9|1\.0|1\.1) [NC,OR]
  4468. RewriteRule .* - [F]
  4469.  
  4470. RewriteCond %{HTTP_COOKIE} ^$
  4471. </pre>
  4472.  
  4473.  
  4474.  
  4475. <h2>Secure WP Super Cache</h2>
  4476. <p>I have actually moved to batcache/memcache, but for WP Super Cache you need to secure that directory to prevent malicious scripts/code from being cached to your disk and then exec'd by the malicous 3rd party.  Disallowing .htaccess files in this uploads dir is also a big performance gain in terms of inode/file lookups.</p>
  4477. <pre class="prettyprint lang-config">
  4478. # faster supercache
  4479. &lt;DirectoryMatch "^/home/.*/sites/.*/htdocs/wp-content/cache/(meta|supercache)"&gt;
  4480. AllowOverride none
  4481. &lt;/DirectoryMatch&gt;
  4482. </pre>
  4483.  
  4484.  
  4485. <h2>Secure WordPress Uploads Folder</h2>
  4486. <p>Stick in your WP <code>/wp-content/uploads/.htaccess</code> file.  Many of the most impactful exploits target plugins such as Gravity Forms that can allow an attacker to upload a malicious image or file that may contain php code or exploit code within its binary, and cause a RCE.  Almost all of the Gravity Form plugins exploits take advantage of it by uploading malformed and malicous php files into the sites uploads folder.  Then the attacker simply requests that uploaded malicous file to trigger it.  The solution is to deny any files in the uploads folder from using any cgi.</p>
  4487. <p>Basically, need to remove any handlers for files in the uploads folder so that its impossible for any interpreter like bash, python, ruby, etc., to run an uploaded file, instead the are forced to be treated as octet-streams which is what they always should be anyways.</p>
  4488. <p>Note that for certain file extensions I am forcing them to be interpreted by Apache as plain text.  This means no interpreters are even contemplated for use in opening an upload file.</p>
  4489. <pre class="prettyprint lang-config">
  4490. # faster and safer uploads
  4491. RemoveHandler .ini .sh .bsh .bash .awk .nawk .gawk .csh .var .c .in .h .asc .md5 .sha .sha1 .cgi .pl .php .inc .asp .exe .bin .py .pl .phtml
  4492. RemoveHandler .out .output .overlay .p12 .p5c .pam .pas .patch .phps .php5 .php4 .php3 .pbxproj .pdb .pdf .pem .perl .phar .php .php_cs .phpize .phpt .pingpong .pipelining .pk
  4493.  
  4494. &lt;FilesMatch "\.(ini|sh|bsh|bash|awk|nawk|gawk|csh|var|c|in|h|asc|md5|sha|sha1|cgi|pl|php|php*|py|inc|asp|exe|bin|list|py|rb|phtml|tag|info|txt)$"&gt;
  4495. ForceType text/plain
  4496. &lt;/FilesMatch&gt;
  4497. </pre>
  4498.  
  4499.  
  4500.  
  4501. <h2>Fix Trackback issues</h2>
  4502. <pre class="prettyprint lang-config">
  4503. # trackback fixes
  4504. RedirectMatch 301 (?i)^(.+)/trackback/?.*$ https://www.askapache.com$1
  4505. </pre>
  4506.  
  4507.  
  4508.  
  4509. <h2>Secure WP Document_Root</h2>
  4510. <h3>Block Logins with empty User Agent</h3>
  4511. <pre class="prettyprint lang-config">
  4512. RewriteCond %{THE_REQUEST} ^POST.*wp-login [NC]
  4513. RewriteCond %{HTTP_USER_AGENT} ^$
  4514. RewriteRule .* - [F]
  4515. </pre>
  4516.  
  4517. <h3>Block Logins with bad cookie</h3>
  4518. <p>You should all be using a custom login cookie name definable with constants in your <code>wp-config.php</code> file.  That means the default cookie <code>wordpress_test_cookie</code> will never be set, so you can block bots that use this default!</p>
  4519. <p>The way to deviate from the default is to set this constant to anything you want in your <code>wp-config.php</code></p>
  4520. <pre>define( &#039;TEST_COOKIE&#039;, &#039;use_this_cookie_name_instead_of_wordpress_test_cookie&#039; );</pre>
  4521. <h3>Block bad test cookies</h3>
  4522. <pre class="prettyprint lang-config">
  4523. RewriteCond %{THE_REQUEST} ^POST.*wp-login [NC]
  4524. RewriteCond %{HTTP:Cookie} "wordpress_test_cookie=WP+Cookie+check" [NC]
  4525. RewriteRule .* - [F]&#039;
  4526. </pre>
  4527.  
  4528. <h3>Block revslider exploit requests</h3>
  4529. <pre class="prettyprint lang-config">RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ .*revslider_show_image.* [NC]
  4530. RewriteRule .* - [F,L]
  4531.  
  4532. RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ .*revslider_show_image.* [NC]
  4533. RewriteCond %{REQUEST_FILENAME} !-f
  4534. RewriteCond %{REQUEST_FILENAME} !-d
  4535. RewriteRule .* - [F,L]
  4536. </pre>
  4537.  
  4538. <h2>Block bad HTTP Protocol and Request Methods</h2>
  4539. <p>Blocks a request method other than GET, POST, HEAD, PROPFIND, and OPTIONS. Also blocks HTTP protocols other than /p0.9, 1.0, and 1.1</p>
  4540. <pre class="prettyprint lang-config">RewriteCond %{THE_REQUEST} !^(POST|GET|HEAD|PROPFIND|OPTIONS)\ .+\ HTTP/(0\.9|1\.0|1\.1) [NC,OR]
  4541. RewriteRule .* - [F,L]
  4542. </pre>
  4543.  
  4544. <h2>Block empty Host Headers</h2>
  4545. <p>A lot of bots will try to make requests against your site using IP's or bad hostnames.  Here's how to block empty HOST header requests.</p>
  4546. <pre class="prettyprint lang-config">
  4547. RewriteCond %{HTTP_HOST} ^$
  4548. RewriteRule .* - [F,L]
  4549. </pre><p><a rel="nofollow" href="https://www.askapache.com/security/stop-wordpress-exploits-spam/">Stopping WordPress Exploits and Spam</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4550. ]]></content:encoded>
  4551. <wfw:commentRss>https://www.askapache.com/security/stop-wordpress-exploits-spam/feed/</wfw:commentRss>
  4552. <slash:comments>0</slash:comments>
  4553. </item>
  4554. <item>
  4555. <title>Ascii World</title>
  4556. <link>https://www.askapache.com/javascript/asciii-world/</link>
  4557. <comments>https://www.askapache.com/javascript/asciii-world/#respond</comments>
  4558. <pubDate>Sat, 30 Apr 2016 01:34:17 +0000</pubDate>
  4559. <dc:creator><![CDATA[AskApache]]></dc:creator>
  4560. <category><![CDATA[Javascript]]></category>
  4561.  
  4562. <guid isPermaLink="false">https://www.askapache.com/?p=9789</guid>
  4563. <description><![CDATA[<p><a rel="nofollow" href="https://www.askapache.com/javascript/asciii-world/">Ascii World</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4564. ]]></description>
  4565. <content:encoded><![CDATA[<a href="http://aem1k.com/world/">http://aem1k.com/world/</a>
  4566. <script>
  4567. eval(z='p="<"+"pre>"/* ,.oq#+     ,._, */;for(y in n="zw24l6k\
  4568. 4e3t4jnt4qj24xh2 x/* =<,m#F^    A W###q. */42kty24wrt413n243n\
  4569. 9h243pdxt41csb yz/* #K       q##H######Am */43iyb6k43pk7243nm\
  4570. r24".split(4)){/* dP      cpq#q##########b, */for(a in t=pars\
  4571. eInt(n[y],36)+/*         p##@###YG=[#######y */(e=x=r=[]))for\
  4572. (r=!r,i=0;t[a/*         d#qg `*PWo##q#######D */]>i;i+=.05)wi\
  4573. th(Math)x-= /*        aem1k.com Q###KWR#### W[ */.05,0<cos(o=\
  4574. new Date/1e3/*      .Q#########Md#.###OP  [email protected] , */-x/PI)&&(e[~\
  4575. ~(32*sin(o)*/* ,    (W#####Xx######.P^     T % */sin(.5+y/7))\
  4576. +60] =-~ r);/* #y    `^TqW####P###BP           */for(x=0;122>\
  4577. x;)p+="   *#"/* b.        OQ####x#K           */[e[x++]+e[x++\
  4578. ]]||(S=("eval"/* l         `X#####D  ,       */+"(z=\'"+z.spl\
  4579. it(B = "\\\\")./*           G####B" #       */join(B+B).split\
  4580. (Q="\'").join(B+Q/*          VQBP`        */)+Q+")//m1k")[x/2\
  4581. +61*y-1]).fontcolor/*         TP         */(/\\w/.test(S)&&"#\
  4582. 03B");document.body.innerHTML=p+=B+"\\n"}setTimeout(z)')//
  4583. </script>
  4584.  
  4585.  
  4586.  
  4587.  
  4588.  
  4589.  
  4590.  
  4591.  
  4592.  
  4593.  
  4594.  
  4595.  
  4596.  
  4597.  
  4598.  
  4599.  
  4600.  
  4601.  
  4602.  
  4603.  
  4604.  
  4605.  
  4606.  
  4607.  
  4608.  
  4609.  
  4610.  
  4611. <p><a rel="nofollow" href="https://www.askapache.com/javascript/asciii-world/">Ascii World</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4612. ]]></content:encoded>
  4613. <wfw:commentRss>https://www.askapache.com/javascript/asciii-world/feed/</wfw:commentRss>
  4614. <slash:comments>0</slash:comments>
  4615. </item>
  4616. <item>
  4617. <title>Success comes before work only in the dictionary</title>
  4618. <link>https://www.askapache.com/hacking/success-never-before-work/</link>
  4619. <comments>https://www.askapache.com/hacking/success-never-before-work/#respond</comments>
  4620. <pubDate>Tue, 26 Jan 2016 00:42:25 +0000</pubDate>
  4621. <dc:creator><![CDATA[AskApache]]></dc:creator>
  4622. <category><![CDATA[Hacking]]></category>
  4623. <category><![CDATA[CS]]></category>
  4624. <category><![CDATA[passion]]></category>
  4625. <category><![CDATA[Tchaikovsky]]></category>
  4626. <category><![CDATA[work ethic]]></category>
  4627. <category><![CDATA[YouTube]]></category>
  4628.  
  4629. <guid isPermaLink="false">https://www.askapache.com/?p=9864</guid>
  4630. <description><![CDATA[<p>Love this Tchaikovsky Violin Concerto in D Major by Jinjoo Cho.  It's a beautiful take on the classic.</p>
  4631. <p><iframe width="300" height="169" src="https://www.youtube.com/embed/iFh5VfR7klw" frameborder="0" allowfullscreen></iframe></p>
  4632. <p><a rel="nofollow" href="https://www.askapache.com/hacking/success-never-before-work/">Success comes before work only in the dictionary</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4633. ]]></description>
  4634. <content:encoded><![CDATA[<p>Love this Tchaikovsky Violin Concerto in D Major by Jinjoo Cho. One of the great things about Violin concertos is how uniquely they can be played.  This is a beautiful way to play this classic.</p>
  4635.  
  4636. <h2>Success only comes before work in the dictionary</h2>
  4637. <p>In all things CS the best are defined by either extraordinary natural talent + great work ethic, or just plain old great work ethic by itself.. but the ones I love to admire are those who gained the title of "best" through dedicated hard work and constant learning.  Some exceptions exist for the once in a generation coders (or musicians like Miles Davis, my personal fav), but note that unless they applied themselves we wouldn't even know about them.</p>
  4638.  
  4639. <p>Shoot for the stars, and you may just end up on the moon, which is much higher than 99.9999% of humans have been at this point.  Though ironically, the moon is much closer.  To scale, the moon is 40 feet away, while the closest star "the sun" would be 3 miles away.</p>
  4640.  
  4641. <p>Or, I may just enjoy this as a sometime amateur violinist (guitar/drums/piano). This piece and composition and execution, just fantastic.  -- and, Jinjoo Cho won the Gold medal in my city at <a href="http://www.carnegiehall.org/Calendar/2016/6/9/0800/PM/Jinjoo-Cho-Violin/">The International Violin Competition of Indianapolis 2014 at Carnegie Hall</a>.</p>
  4642.  
  4643.  
  4644. <h2>Support your local musicians</h2>
  4645. <iframe width="730" height="411" src="https://www.youtube.com/embed/iFh5VfR7klw?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>
  4646. <p><a rel="nofollow" href="https://www.askapache.com/hacking/success-never-before-work/">Success comes before work only in the dictionary</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4647. ]]></content:encoded>
  4648. <wfw:commentRss>https://www.askapache.com/hacking/success-never-before-work/feed/</wfw:commentRss>
  4649. <slash:comments>0</slash:comments>
  4650. </item>
  4651. <item>
  4652. <title>The Website Obesity Crisis</title>
  4653. <link>https://www.askapache.com/optimize/website-obesity-crisis/</link>
  4654. <comments>https://www.askapache.com/optimize/website-obesity-crisis/#respond</comments>
  4655. <pubDate>Fri, 08 Jan 2016 17:09:39 +0000</pubDate>
  4656. <dc:creator><![CDATA[AskApache]]></dc:creator>
  4657. <category><![CDATA[Optimization]]></category>
  4658. <category><![CDATA[bloat]]></category>
  4659. <category><![CDATA[PageSpeed]]></category>
  4660. <category><![CDATA[performance]]></category>
  4661. <category><![CDATA[speed]]></category>
  4662.  
  4663. <guid isPermaLink="false">https://www.askapache.com/?p=9767</guid>
  4664. <description><![CDATA[<p><a href="http://idlewords.com/talks/website_obesity.htm"><img src="https://www.askapache.com/s/u.askapache.com/2016/01/image-1.jpeg" alt="Adding a 51st lane wont help" width="260" height="146" class="IFL" /></p>
  4665. <p><span>http://idlewords.com/talks/website_obesity.htm</span><br class="C" /></a></p>
  4666. <p><a rel="nofollow" href="https://www.askapache.com/optimize/website-obesity-crisis/">The Website Obesity Crisis</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4667. ]]></description>
  4668. <content:encoded><![CDATA[<p>Very insightful article and video you must read.  Esp. if you work at Google, Facebook, Amazon, Yahoo, Apple, etc.</p>
  4669. <h2>The Web Obesity Crisis</h2>
  4670. <p><a href="http://idlewords.com/talks/website_obesity.htm"><img src="https://www.askapache.com/s/u.askapache.com/2016/01/image-1.jpeg" alt="Adding a 51st lane wont help" width="260" height="146" class="IFL" /><br /><br /><br /><span>http://idlewords.com/talks/website_obesity.htm</span><br class="C" /></a></p><p><a rel="nofollow" href="https://www.askapache.com/optimize/website-obesity-crisis/">The Website Obesity Crisis</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4671. ]]></content:encoded>
  4672. <wfw:commentRss>https://www.askapache.com/optimize/website-obesity-crisis/feed/</wfw:commentRss>
  4673. <slash:comments>0</slash:comments>
  4674. </item>
  4675. <item>
  4676. <title>MySQL Performance Tuning Scripts and Know-How</title>
  4677. <link>https://www.askapache.com/mysql/mysql-performance-tuning/</link>
  4678. <comments>https://www.askapache.com/mysql/mysql-performance-tuning/#comments</comments>
  4679. <pubDate>Fri, 30 Oct 2015 07:33:20 +0000</pubDate>
  4680. <dc:creator><![CDATA[AskApache]]></dc:creator>
  4681. <category><![CDATA[MySQL]]></category>
  4682. <category><![CDATA[InnoDB]]></category>
  4683. <category><![CDATA[linux]]></category>
  4684. <category><![CDATA[MariaDB]]></category>
  4685. <category><![CDATA[my.cnf]]></category>
  4686. <category><![CDATA[MyISAM]]></category>
  4687. <category><![CDATA[Optimization]]></category>
  4688. <category><![CDATA[Percona]]></category>
  4689. <category><![CDATA[performance]]></category>
  4690. <category><![CDATA[phpMyAdmin]]></category>
  4691.  
  4692. <guid isPermaLink="false">https://www.askapache.com/?p=9072</guid>
  4693. <description><![CDATA[<p><a href="https://www.askapache.com/mysql/performance-tuning-mysql/" class="IFL"><img src="https://www.askapache.com/s/u.askapache.com/2013/07/mysql-tuning-primer.png" alt="mysql-tuning-primer" width="438" height="176" class="alignnone size-full wp-image-9120" /></a>Unless you are a total linux-freak-guru like myself, and even if you are, it can be enormously challenging and somewhat overwhelming to locate and eliminate MySQL bottlenecks. While many DBAs focus on improving the performance of the queries themselves, this post will focus on the highest-impact items:  MySQL Server Performance and OS Performance for MySQL.  Specifically showing <a href="https://www.askapache.com/mysql/performance-tuning-mysql/">4 awesome tools to auto-tune your MySQL</a> and a few more tools just for monitoring!<br class="C" /></p>
  4694. <p><a rel="nofollow" href="https://www.askapache.com/mysql/mysql-performance-tuning/">MySQL Performance Tuning Scripts and Know-How</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4695. ]]></description>
  4696. <content:encoded><![CDATA[<p>Unless you are a MySQL performance tuning expert, it can be enormously challenging and somewhat overwhelming to locate and eliminate MySQL bottlenecks. While many DBAs focus on improving the performance of the queries themselves, this post will focus on the highest-impact non-query items:  MySQL Server Performance and OS Performance for MySQL.</p>
  4697.  
  4698. <h2>MySQL Performance Tuning</h2>
  4699. <p>This post is a "best-of" compilation of the tricks and scripts I have found to be the most effective over the past decade.  I'd like to write a 50 page article but am limiting this to 1 page.</p>
  4700. <p>For anyone serious about High Performance MySQL, I would highly highly recommend the fantastic book: "<strong>High Performance MySQL</strong>: Optimization, Backups, Replication, and more" - O'Reilly.  I have spent many hours poring over it's wisdom-filled pages and gaining much practical know-how.</p>
  4701.  
  4702. <h2>MySQL Server Software</h2>
  4703. <p>Each new MySQL server release contains ENORMOUS performance enhancements over previous versions.  That is the absolute very first thing you should do:  Upgrade your MySQL Server and Client libraries and keep them updated.</p>
  4704. <p>There are several "flavors" of MySQL believe it or not.. Most people use the stock MySQL Server.  I, along with WikiPedia, Arch-Linux, and others, use MariaDB.  MariaDB is a greatly enhanced 100% compatible replacement for the stock MySQL Server.  It is based on the excellent work by the Percona project.  The percona flavor of MySQL is the other truly improved version of MySQL to consider.  I personally have spent a couple years using Percona, then I upgraded from Percona to MariaDB (which has a lot of Percona juju built in) and am no longer thinking about which version to go with.  MariaDB is the bomb-diggity.</p>
  4705.  
  4706.  
  4707. <h3>MySQL Engine</h3>
  4708. <p>InnoDB not MyISAM.  InnoDB may be surpassed by in-development engines like TokuDB.  I ONLY use InnoDB, for everything.</p>
  4709.  
  4710. <h3>Types of MySQL Servers to optimize</h3>
  4711. <p>Seriously?  Optimize EVERYTHING!  The screenshots below are actual from one of my live servers.  That server used to be 8GB RAM, but now as you may see in the screenshots, it is now only 2GB of RAM.  I was able to save some serious $$$ by optimizing my server, without sacrificing speed... In fact I gained some speed in many instances.</p>
  4712. <p>I've used these optimization techniques on monster servers with 32GB of ram and many slaves, and also on a machine with 1GB of ram (running arch-linux).</p>
  4713.  
  4714. <h2>MySQL Performance Tuning Scripts</h2>
  4715. <p>The first thing to understand and believe is that there is <strong>absolutely no substitute</strong> for having a professional tune your DB.  I personally use 2 professionals to tune clients DBs... I optimize it first, then I optimize it again after both pros are finished.</p>
  4716. <ol>
  4717. <li>A DBA who knows MySQL optimization inside and out, percona/mariadb experience = "the best".</li>
  4718. <li>A Linux system admin GURU who can make sure the subtle and not-so-subtle settings and tweaks to the OS is geared for max performance.</li>
  4719. </ol>
  4720. <p>If you are just learning or doing it yourself, props to you!  In that case, you should utilize ALL 4 of these tools.  The one thing you need to do before running any of them is make sure your MySQL server has been online for at least a week without restarting, otherwise the results will mostly all be questionable.  I especially like the Tuning-Primer shell script, and the phpMyAdmin Advisor (<em>which is fairly new to phpMyAdmin - using 4.1-DEV-BETA</em>).</p>
  4721. <p>The biggest areas to focus in on (IMHO) are:</p>
  4722. <ol>
  4723. <li>MEMORY/RAM, specifically the buffers</li>
  4724. <li>SWAP</li>
  4725. <li>ACID - Do you need full ACID, or can you (likely) make some sacrifices there for speed</li>
  4726. <li>tmp tables, tmpdir (use a tmpfs mounted dir)</li>
  4727. <li>Thread/Connections - How many processes and threads should be running</li>
  4728. <li>open_files / table_cache - May need to boost your <code>/etc/security/limits.conf</code> and your <code>/etc/sysctl.conf</code></li>
  4729. </ol>
  4730.  
  4731.  
  4732. <h3>Tuning-Primer</h3>
  4733. <p><a href="https://launchpad.net/mysql-tuning-primer">MySQL Tuning Primer Script</a> - tuning-primer.sh - This script takes information from "<code>SHOW STATUS LIKE</code>..." and "<code>SHOW VARIABLES LIKE</code>..." then attempts to produce sane recommendations for tuning server variables. It is compatible with all versions of MySQL 3.23 and above.</p>
  4734. <p><a href="https://www.askapache.com/s/u.askapache.com/2013/07/tuning-primer.png"><img src="https://www.askapache.com/s/u.askapache.com/2013/07/tuning-primer.png" alt="MySQL Performance Tuning Script: Tuning-Primer" width="486" height="505" /></a></p>
  4735. <ul>
  4736. <li><a href="http://www.day32.com/MySQL/">Sundry MySQL Scripts and Docs</a></li>
  4737. <li><a href="https://launchpad.net/mysql-tuning-primer">MySQL Tuning Primer Script</a></li>
  4738. </ul>
  4739.  
  4740. <h3>phpMyAdmin Advisor</h3>
  4741. <p>This tool is very similar to the tuning-primer tool.  Nice and fast, and likely the most up-to-date tool.</p>
  4742. <p><a href="https://www.askapache.com/s/u.askapache.com/2013/07/phpmyadmin-advisor.png"><img src="https://www.askapache.com/s/u.askapache.com/2013/07/phpmyadmin-advisor.png" alt="MySQL Performance Tuning Script: phpmyadmin-advisor" width="755" height="305" class="alignnone size-full wp-image-9105" /></a></p>
  4743.  
  4744. <h3>MySQLTuner</h3>
  4745. <p><a href="https://github.com/major/MySQLTuner-perl">MySQLTuner</a>: a script written in Perl that will assist you with your MySQL configuration and make recommendations for increased performance and stability.</p>
  4746. <p><a href="https://www.askapache.com/s/u.askapache.com/2013/07/mysqltuner.png"><img src="https://www.askapache.com/s/u.askapache.com/2013/07/mysqltuner.png" alt="MySQL Performance Tuning Script: mysqltuner" width="488" height="588" /></a></p>
  4747.  
  4748. <h3>mysqlreport</h3>
  4749. <p><a href="http://hackmysql.com/mysqlreport">mysqlreport</a>: makes a friendly report of important MySQL status values. mysqlreport transforms the values from SHOW STATUS into an easy-to-read report that provides an in-depth understanding of how well MySQL is running. mysqlreport is a better alternative (and practically the only alternative) to manually interpreting SHOW STATUS.</p>
  4750. <ul>
  4751. <li><a href="http://hackmysql.com/mysqlreportguide">The Guide To Understanding mysqlreport</a></li>
  4752. <li><a href="http://hackmysql.com/mysqlreportdoc">mysqlreport Documentation</a></li>
  4753. </ul>
  4754. <p><a href="https://www.askapache.com/s/u.askapache.com/2013/07/mysqlreport.png"><img src="https://www.askapache.com/s/u.askapache.com/2013/07/mysqlreport.png" alt="MySQL Performance Tuning Script: mysqlreport" width="443" height="584" /></a></p>
  4755.  
  4756.  
  4757. <h3>Percona Tools for MySQL</h3>
  4758. <p>Free online productivity tools for MySQL DBAs, SysAdmins and Developers</p>
  4759. <p><a href="https://tools.percona.com/wizard"><img src="https://www.askapache.com/s/u.askapache.com/2013/07/percona-tools-for-mysql-300x295.png" alt="percona-tools-for-mysql" width="300" height="295" class="alignnone size-medium wp-image-9496" /></a></p>
  4760. <p><a href="https://tools.percona.com/wizard">Percona Configuration Wizard for MySQL</a></p>
  4761. <p>Apply Percona best practices to achieve better MySQL database performance and avoid the time, complexity, and risk of customizing a my.cnf configuration on your own. Simply copy and paste the results of the Percona Configuration Wizard for MySQL into your my.cnf file.</p>
  4762. <p>Tens of thousands of MySQL users have already used this tool to improve their MySQL performance</p>
  4763.  
  4764.  
  4765. <h2>Monitoring MySQL</h2>
  4766. <p>The mysqladmin command is great and all, but these 3 tools are much more useful for the specialized task of monitoring MySQL.  The most powerful is innotop, then mytop, and finally the phpMyAdmin Monitor is great for general big-picture monitoring.  Also, make sure you understand and use slow query logging and <code>mysqldumpslow</code> as well.</p>
  4767.  
  4768. <h3>mytop</h3>
  4769. <p><a href="http://jeremy.zawodny.com/mysql/mytop/">mytop</a> - a top clone for MySQL.</p>
  4770. <p><a href="https://www.askapache.com/s/u.askapache.com/2013/07/mytop1.png"><img src="https://www.askapache.com/s/u.askapache.com/2013/07/mytop1.png" alt="mytop" width="521" height="119" /></a></p>
  4771.  
  4772. <h3>innotop</h3>
  4773. <p><a href="http://code.google.com/p/innotop/">innotop</a></p>
  4774. <ul>
  4775. <li><a href="http://www.linux-mag.com/id/7646/">InnoDB Performance Monitoring with innotop</a></li>
  4776. <li><a href="http://www.mysqlperformanceblog.com/2012/11/22/get-me-some-query-logs/">Get me some Query Logs</a></li>
  4777. </ul>
  4778. <p><a href="https://www.askapache.com/s/u.askapache.com/2013/07/innotop.png"><img src="https://www.askapache.com/s/u.askapache.com/2013/07/innotop.png" alt="innotop" width="444" height="422" /></a></p>
  4779.  
  4780. <h3>phpMyAdmin Monitor</h3>
  4781. <p><a href="https://www.askapache.com/s/u.askapache.com/2013/07/phpmyadmin-monitoring.png"><img src="https://www.askapache.com/s/u.askapache.com/2013/07/phpmyadmin-monitoring.png" alt="phpmyadmin-monitoring" width="643" height="287" class="alignnone size-full wp-image-9106" /></a></p>
  4782.  
  4783.  
  4784.  
  4785.  
  4786.  
  4787.  
  4788. <h2>More Resources</h2>
  4789. <ul>
  4790. <li><a href="https://www.kernel.org/doc/Documentation/sysctl/fs.txt">https://www.kernel.org/doc/Documentation/sysctl/fs.txt</a></li>
  4791. <li>Percona Configuration Wizard for MySQL</li>
  4792. <li><a href="https://kb.askmonty.org/en/optimization-and-tuning/">Optimization and Tuning Articles on how to get the most out of MariaDB, including new features.</a></li>
  4793. <li><a href="https://kb.askmonty.org/en/slow-query-log-overview/">Slow Query Log Overview</a></li>
  4794. <li><a href="http://www.serveradminblog.com/2011/03/tuning-mysql-performance-howto-part-1/">MySQL Performance – Howto – part 1 (high performance tuning scripts)</a>, <a href="http://www.serveradminblog.com/2010/02/sysbench-on-centos-howto/">SysBench on CentOS – HowTo - Part 2</a></li>
  4795. <li><a href="http://www.percona.com/doc/percona-toolkit/2.2/pt-query-digest.html">pt-query-digest</a> - Analyze MySQL queries from logs, processlist, and tcpdump.</li>
  4796. </ul><p><a rel="nofollow" href="https://www.askapache.com/mysql/mysql-performance-tuning/">MySQL Performance Tuning Scripts and Know-How</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4797. ]]></content:encoded>
  4798. <wfw:commentRss>https://www.askapache.com/mysql/mysql-performance-tuning/feed/</wfw:commentRss>
  4799. <slash:comments>3</slash:comments>
  4800. </item>
  4801. <item>
  4802. <title>Mod_Rewrite Variables Cheatsheet</title>
  4803. <link>https://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet/</link>
  4804. <comments>https://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet/#comments</comments>
  4805. <pubDate>Tue, 15 Sep 2015 15:05:23 +0000</pubDate>
  4806. <dc:creator><![CDATA[AskApache]]></dc:creator>
  4807. <category><![CDATA[Htaccess]]></category>
  4808. <category><![CDATA[Apache]]></category>
  4809. <category><![CDATA[cheatsheet]]></category>
  4810. <category><![CDATA[htaccess file]]></category>
  4811. <category><![CDATA[mod_rewrite]]></category>
  4812. <category><![CDATA[PHP]]></category>
  4813. <category><![CDATA[rewrite]]></category>
  4814. <category><![CDATA[Rewriting]]></category>
  4815.  
  4816. <guid isPermaLink="false">https://www.askapache.com/?p=1280</guid>
  4817. <description><![CDATA[<p><a class="IFL" href="https://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet/" title="mod_rewrite cheatsheet for .htaccess rewrites"><img src="https://www.askapache.com/s/u.askapache.com/2012/11/skull.png" alt="skull" width="165" height="141" /></a>We've figured out what <a href="https://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial/">mod_rewrite variables</a> look like, a cheatsheet of the actual value. <br class="C" /></p>
  4818. <p><a rel="nofollow" href="https://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet/">Mod_Rewrite Variables Cheatsheet</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  4819. ]]></description>
  4820. <content:encoded><![CDATA[<p><a class="IFL" href="https://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet/" title="mod_rewrite cheatsheet for .htaccess rewrites"><img src="https://www.askapache.com/s/u.askapache.com/2012/11/skull.png" alt="mod_rewrite cheatsheet for .htaccess rewrites" width="165" height="141" /></a>We've figured out what <a href="https://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial/">mod_rewrite variables</a> look like so we can create rewrite rules and condition patterns based on the actual value.  This cheatsheet is where we'll lay them all out for quick reference.  This cheatsheet changed my life.<br /><br />Here the focus is on identifying mod_rewrite variables and defining the limits of the module by checking the <a href='https://www.askapache.com/pub/servers/mod_rewrite.c.html'>mod_rewrite source code</a>.<br class="C" /></p>
  4821.  
  4822.  
  4823.  
  4824. <h2>Apache Mod_Rewrite Variables</h2>
  4825. <ul>
  4826. <li><a href="#API_VERSION">API_VERSION</a></li>
  4827. <li><a href="#AUTH_TYPE">AUTH_TYPE</a></li>
  4828. <li><a href="#CONTENT_LENGTH">CONTENT_LENGTH</a></li>
  4829. <li><a href="#CONTENT_TYPE">CONTENT_TYPE</a></li>
  4830. <li><a href="#DOCUMENT_ROOT">DOCUMENT_ROOT</a></li>
  4831. <li><a href="#GATEWAY_INTERFACE">GATEWAY_INTERFACE</a></li>
  4832. <li><a href="#IS_SUBREQ">IS_SUBREQ</a></li>
  4833. <li><a href="#ORIG_PATH_INFO">ORIG_PATH_INFO</a></li>
  4834. <li><a href="#ORIG_PATH_TRANSLATED">ORIG_PATH_TRANSLATED</a></li>
  4835. <li><a href="#ORIG_SCRIPT_FILENAME">ORIG_SCRIPT_FILENAME</a></li>
  4836. <li><a href="#ORIG_SCRIPT_NAME">ORIG_SCRIPT_NAME</a></li>
  4837. <li><a href="#PATH">PATH</a></li>
  4838. <li><a href="#PATH_INFO">PATH_INFO</a></li>
  4839. <li><a href="#PHP_SELF">PHP_SELF</a></li>
  4840. <li><a href="#QUERY_STRING">QUERY_STRING</a></li>
  4841. <li><a href="#REDIRECT_QUERY_STRING">REDIRECT_QUERY_STRING</a></li>
  4842. <li><a href="#REDIRECT_REMOTE_USER">REDIRECT_REMOTE_USER</a></li>
  4843. <li><a href="#REDIRECT_STATUS">REDIRECT_STATUS</a></li>
  4844. <li><a href="#REDIRECT_URL">REDIRECT_URL</a></li>
  4845. <li><a href="#REMOTE_ADDR">REMOTE_ADDR</a></li>
  4846. <li><a href="#REMOTE_HOST">REMOTE_HOST</a></li>
  4847. <li><a href="#REMOTE_IDENT">REMOTE_IDENT</a></li>
  4848. <li><a href="#REMOTE_PORT">REMOTE_PORT</a></li>
  4849. <li><a href="#REMOTE_USER">REMOTE_USER</a></li>
  4850. <li><a href="#REQUEST_FILENAME">REQUEST_FILENAME</a></li>
  4851. <li><a href="#REQUEST_METHOD">REQUEST_METHOD</a></li>
  4852. <li><a href="#REQUEST_TIME">REQUEST_TIME</a></li>
  4853. <li><a href="#REQUEST_URI">REQUEST_URI</a></li>
  4854. <li><a href="#SCRIPT_FILENAME">SCRIPT_FILENAME</a></li>
  4855. <li><a href="#SCRIPT_GROUP">SCRIPT_GROUP</a></li>
  4856. <li><a href="#SCRIPT_NAME">SCRIPT_NAME</a></li>
  4857. <li><a href="#SCRIPT_URI">SCRIPT_URI</a></li>
  4858. <li><a href="#SCRIPT_URL">SCRIPT_URL</a></li>
  4859. <li><a href="#SCRIPT_USER">SCRIPT_USER</a></li>
  4860. <li><a href="#SERVER_ADDR">SERVER_ADDR</a></li>
  4861. <li><a href="#SERVER_ADMIN">SERVER_ADMIN</a></li>
  4862. <li><a href="#SERVER_NAME">SERVER_NAME</a></li>
  4863. <li><a href="#SERVER_PORT">SERVER_PORT</a></li>
  4864. <li><a href="#SERVER_PROTOCOL">SERVER_PROTOCOL</a></li>
  4865. <li><a href="#SERVER_SIGNATURE">SERVER_SIGNATURE</a></li>
  4866. <li><a href="#SERVER_SOFTWARE">SERVER_SOFTWARE</a></li>
  4867. <li><a href="#THE_REQUEST">THE_REQUEST</a></li>
  4868. <li><a href="#TIME">TIME</a></li>
  4869. <li><a href="#TIME_DAY">TIME_DAY</a></li>
  4870. <li><a href="#TIME_HOUR">TIME_HOUR</a></li>
  4871. <li><a href="#TIME_MIN">TIME_MIN</a></li>
  4872. <li><a href="#TIME_MON">TIME_MON</a></li>
  4873. <li><a href="#TIME_SEC">TIME_SEC</a></li>
  4874. <li><a href="#TIME_WDAY">TIME_WDAY</a></li>
  4875. <li><a href="#TIME_YEAR">TIME_YEAR</a></li>
  4876. <li><a href="#TZ">TZ</a></li>
  4877. <li><a href="#UNIQUE_ID">UNIQUE_ID</a></li>
  4878. </ul>
  4879.  
  4880. <p>HTTP Variables</p>
  4881. <ul>
  4882. <li><a href="#HTTP_ACCEPT">HTTP_ACCEPT</a></li>
  4883. <li><a href="#HTTP_ACCEPT_CHARSET">HTTP_ACCEPT_CHARSET</a></li>
  4884. <li><a href="#HTTP_ACCEPT_ENCODING">HTTP_ACCEPT_ENCODING</a></li>
  4885. <li><a href="#HTTP_ACCEPT_LANGUAGE">HTTP_ACCEPT_LANGUAGE</a></li>
  4886. <li><a href="#HTTP_CACHE_CONTROL">HTTP_CACHE_CONTROL</a></li>
  4887. <li><a href="#HTTP_CONNECTION">HTTP_CONNECTION</a></li>
  4888. <li><a href="#HTTP_COOKIE">HTTP_COOKIE</a></li>
  4889. <li><a href="#HTTP_FORWARDED">HTTP_FORWARDED</a></li>
  4890. <li><a href="#HTTP_HOST">HTTP_HOST</a></li>
  4891. <li><a href="#HTTP_KEEP_ALIVE">HTTP_KEEP_ALIVE</a></li>
  4892. <li><a href="#HTTP_PROXY_CONNECTION">HTTP_PROXY_CONNECTION</a></li>
  4893. <li><a href="#HTTP_REFERER">HTTP_REFERER</a></li>
  4894. <li><a href="#HTTP_USER_AGENT">HTTP_USER_AGENT</a></li>
  4895. </ul>
  4896.  
  4897.  
  4898. <p>SSL Variables</p>
  4899. <ul>
  4900. <li><a href="#HTTPS">HTTPS</a></li>
  4901. <li><a href="#SSL_CIPHER">SSL_CIPHER</a></li>
  4902. <li><a href="#SSL_CIPHER_ALGKEYSIZE">SSL_CIPHER_ALGKEYSIZE</a></li>
  4903. <li><a href="#SSL_CIPHER_EXPORT">SSL_CIPHER_EXPORT</a></li>
  4904. <li><a href="#SSL_CIPHER_USEKEYSIZE">SSL_CIPHER_USEKEYSIZE</a></li>
  4905. <li><a href="#SSL_CLIENT_VERIFY">SSL_CLIENT_VERIFY</a></li>
  4906. <li><a href="#SSL_PROTOCOL">SSL_PROTOCOL</a></li>
  4907. <li><a href="#SSL_SERVER_A_KEY">SSL_SERVER_A_KEY</a></li>
  4908. <li><a href="#SSL_SERVER_A_SIG">SSL_SERVER_A_SIG</a></li>
  4909. <li><a href="#SSL_SERVER_CERT">SSL_SERVER_CERT</a></li>
  4910. <li><a href="#SSL_SERVER_I_DN">SSL_SERVER_I_DN</a></li>
  4911. <li><a href="#SSL_SERVER_I_DN_C">SSL_SERVER_I_DN_C</a></li>
  4912. <li><a href="#SSL_SERVER_I_DN_CN">SSL_SERVER_I_DN_CN</a></li>
  4913. <li><a href="#SSL_SERVER_I_DN_L">SSL_SERVER_I_DN_L</a></li>
  4914. <li><a href="#SSL_SERVER_I_DN_O">SSL_SERVER_I_DN_O</a></li>
  4915. <li><a href="#SSL_SERVER_I_DN_OU">SSL_SERVER_I_DN_OU</a></li>
  4916. <li><a href="#SSL_SERVER_I_DN_ST">SSL_SERVER_I_DN_ST</a></li>
  4917. <li><a href="#SSL_SERVER_M_SERIAL">SSL_SERVER_M_SERIAL</a></li>
  4918. <li><a href="#SSL_SERVER_M_VERSION">SSL_SERVER_M_VERSION</a></li>
  4919. <li><a href="#SSL_SERVER_S_DN">SSL_SERVER_S_DN</a></li>
  4920. <li><a href="#SSL_SERVER_S_DN_CN">SSL_SERVER_S_DN_CN</a></li>
  4921. <li><a href="#SSL_SERVER_S_DN_O">SSL_SERVER_S_DN_O</a></li>
  4922. <li><a href="#SSL_SERVER_S_DN_OU">SSL_SERVER_S_DN_OU</a></li>
  4923. <li><a href="#SSL_SERVER_V_END">SSL_SERVER_V_END</a></li>
  4924. <li><a href="#SSL_SERVER_V_START">SSL_SERVER_V_START</a></li>
  4925. <li><a href="#SSL_SESSION_ID">SSL_SESSION_ID</a></li>
  4926. <li><a href="#SSL_VERSION_INTERFACE">SSL_VERSION_INTERFACE</a></li>
  4927. <li><a href="#SSL_VERSION_LIBRARY">SSL_VERSION_LIBRARY</a></li>
  4928. </ul>
  4929.  
  4930.  
  4931.  
  4932.  
  4933.  
  4934.  
  4935.  
  4936. <h2>Variable Values and Examples</h2>
  4937. <dl class="dl1">
  4938. <dt><a id="API_VERSION"></a><br />API_VERSION</a>: <code>20020903:12</code></dt>
  4939. <dd><pre class="prettyprint lang-config">RewriteCond %{API_VERSION} ^(.*)$
  4940. RewriteRule .* https://www.askapache.com?API_VERSION=%1 [R=307,L]</pre></dd>
  4941. <dt><a id="AUTH_TYPE"></a><br />AUTH_TYPE</a>: <code>Digest</code></dt>
  4942. <dd><pre class="prettyprint lang-config">RewriteRule .* - [E=IN_AUTH_TYPE:%{AUTH_TYPE}]
  4943. RequestHeader set AUTH_TYPE "%{IN_AUTH_TYPE}e"</pre></dd>
  4944. <dt><a id="CACHE_CONTROL"></a><br />CACHE_CONTROL</a>: <code>max-age=0</code></dt>
  4945. <dd><pre class="prettyprint lang-config">RewriteCond %{ENV:CACHE_CONTROL} no-cache [NC]
  4946. RewriteRule . %{REQUEST_URI}?nocache [L]</pre></dd>
  4947. <dt><a id="CONNECTION"></a><br />CONNECTION</a>: <code>keep-alive</code></dt><dd></dd>
  4948. <dt><a id="CONTENT_LENGTH"></a><br />CONTENT_LENGTH</a>: <code>(null)</code></dt>
  4949. <dd><pre class="prettyprint lang-config">RewriteCond %{REQUEST_METHOD} =POST
  4950. RewriteCond %{HTTP:Content-Length}%{CONTENT_LENGTH} ^$
  4951. RewriteRule .* - [F,NS,L]</pre></dd>
  4952. <dt><a id="CONTENT_TYPE"></a><br />CONTENT_TYPE</a>: <code>(null)</code></dt><dd></dd>
  4953. <dt><a id="DOCUMENT_ROOT"></a><br />DOCUMENT_ROOT</a>: <code>/web/webroot/askapache.com</code></dt>
  4954. <dd><pre class="prettyprint lang-config">RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI}/index.html -f
  4955. RewriteRule . /cache%{REQUEST_URI}/index.html</pre></dd>
  4956. <dt><a id="HOST"></a><br />HOST</a>: <code>www.askapache.com</code></dt>
  4957. <dd><pre class="prettyprint lang-config">RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
  4958. RewriteRule . https://www.askapache.com%{REQUEST_URI} [R=301,L]</pre></dd>
  4959. <dt><a id="HTTP"></a><br />HTTP</a>:</dt>
  4960. <dd><pre class="prettyprint lang-config">RewriteCond %{HTTP:Accept-Encoding} gzip [NC]
  4961. RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.gz -f
  4962. RewriteRule . %{REQUEST_URI}.gz [L]</pre></dd>
  4963. <dt><a id="HTTP_ACCEPT"></a><br />HTTP_ACCEPT</a>: <code>text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8</code></dt><dd></dd>
  4964. <dt><a id="HTTP_COOKIE"></a><br />HTTP_COOKIE</a>: <code>__qca=1176541205adf28-5553185; ASKAPACHEID=fdadfa4f33e62a878468; __utmc=1df3893</code></dt>
  4965. <dd><pre class="prettyprint lang-config">RewriteCond %{HTTP_COOKIE} ^.*autostart=on.*$
  4966. RewriteRule ^(.*)\.swf$ /$1?autostart=true [NE,L]</pre></dd>
  4967. <dt><a id="HTTP_HOST"></a><br />HTTP_HOST</a>: <code>www.askapache.com</code></dt><dd></dd>
  4968. <dt><a id="HTTP_REFERER"></a><br />HTTP_REFERER</a>: <code>https://www.askapache.com/pro/mod_rewrite/catch.php?k=i</code></dt>
  4969. <dd><pre class="prettyprint lang-config">RewriteCond %{HTTP_REFERER} badhost [NC]
  4970. RewriteRule . - [F]</pre></dd>
  4971. <dt><a id="HTTP_USER_AGENT"></a><br />HTTP_USER_AGENT</a>: <code>Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Firefox/3.0.1</code></dt>
  4972. <dd><pre class="prettyprint lang-config">RewriteCond %{HTTP_USER_AGENT} ^.*(Android|2\.0 MMP|240x320|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|EudoraWeb|hiptop|IEMobile|iPhone).*$ [NC]
  4973. RewriteRule ^(.+)$ /mobile/$1 [L]</pre></dd>
  4974. <dt><a id="IS_SUBREQ"></a><br />IS_SUBREQ</a>: <code>false</code></dt><dd></dd>
  4975. <dt><a id="KEEP_ALIVE"></a><br />KEEP_ALIVE</a>: <code>300</code></dt><dd></dd>
  4976. <dt><a id="PATH"></a><br />PATH</a>: <code>/bin:/usr/bin:/sbin:/usr/sbin</code></dt><dd></dd>
  4977. <dt><a id="QUERY_STRING"></a><br />QUERY_STRING</a>: <code>k=i</code></dt>
  4978. <dd><pre class="prettyprint lang-config">RewriteCond %{QUERY_STRING} showtime [NC]
  4979. RewriteCond T:%{TIME}_TY:%{TIME_YEAR}_TMO:%{TIME_MON}_TWD:%{TIME_WDAY}_TD:%{TIME_DAY}_TH:%{TIME_HOUR}_TMI:%{TIME_MIN}_TS:%{TIME_SEC} ^(.*)$
  4980. RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}?time=%1 [R,L]</pre></dd>
  4981. <dt><a id="REMOTE_ADDR"></a><br />REMOTE_ADDR</a>: <code>22.162.134.211</code></dt>
  4982. <dd><pre class="prettyprint lang-config">RewriteCond %{REMOTE_ADDR} !^22\.162\.134\.211$
  4983. RewriteRule . https://www.askapache.com/maintenance-in-progress.html [R=307,L]</pre></dd>
  4984. <dt><a id="REMOTE_HOST"></a><br />REMOTE_HOST</a>: <code>22.162.134.211</code></dt><dd></dd>
  4985. <dt><a id="REMOTE_PORT"></a><br />REMOTE_PORT</a>: <code>4220</code></dt><dd></dd>
  4986. <dt><a id="REMOTE_USER"></a><br />REMOTE_USER</a>: <code>askapache</code></dt>
  4987. <dd><pre class="prettyprint lang-config">RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]</pre></dd>
  4988. <dt><a id="REQUEST_FILENAME"></a><br />REQUEST_FILENAME</a>: <code>/web/webroot/askapache.com/pro/mod_rewrite/index.php</code></dt><dd></dd>
  4989. <dt><a id="REQUEST_METHOD"></a><br />REQUEST_METHOD</a>: <code>GET</code></dt>
  4990. <dd><pre class="prettyprint lang-config">RewriteCond %{REQUEST_METHOD} !^(POST|GET|HEAD|PROPFIND|OPTIONS)$
  4991. RewriteRule .* - [F,L]</pre></dd>
  4992. <dt><a id="REQUEST_PROTOCOL"></a><br />REQUEST_PROTOCOL</a>: <code>HTTP/1.1</code></dt>
  4993. <dd><pre class="prettyprint lang-config">RewriteCond %{REQUEST_PROTOCOL} !^HTTP/(0\.9|1\.[01])$
  4994. RewriteRule . [F,L]</pre></dd>
  4995. <dt><a id="REQUEST_URI"></a><br />REQUEST_URI</a>: <code>/pro/mod_rewrite/index.php</code></dt>
  4996. <dd><pre class="prettyprint lang-config">RewriteCond %{REQUEST_URI} ^(robots\.txt|favicon\.ico)$ [NC]
  4997. RewriteRule . - [S=1]
  4998. RewriteCond %{HTTP_HOST} ^www
  4999. RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]</pre></dd>
  5000. <dt><a id="SCRIPT_FILENAME"></a><br />SCRIPT_FILENAME</a>: <code>/web/webroot/askapache.com/pro/mod_rewrite/index.php</code></dt><dd></dd>
  5001. <dt><a id="SCRIPT_GROUP"></a><br />SCRIPT_GROUP</a>: <code>daemong</code></dt><dd></dd>
  5002. <dt><a id="SCRIPT_URI"></a><br />SCRIPT_URI</a>: <code>https://www.askapache.com/pro/mod_rewrite/index.php</code></dt><dd></dd>
  5003. <dt><a id="SCRIPT_URL"></a><br />SCRIPT_URL</a>: <code>/pro/mod_rewrite/index.php</code></dt><dd></dd>
  5004. <dt><a id="SCRIPT_USER"></a><br />SCRIPT_USER</a>: <code>askapache</code></dt><dd></dd>
  5005. <dt><a id="SERVER_ADDR"></a><br />SERVER_ADDR</a>: <code>208.113.134.190</code></dt><dd></dd>
  5006. <dt><a id="SERVER_ADMIN"></a><br />SERVER_ADMIN</a>: <code>[email protected]</code></dt><dd></dd>
  5007. <dt><a id="SERVER_NAME"></a><br />SERVER_NAME</a>: <code>www.askapache.com</code></dt><dd></dd>
  5008. <dt><a id="SERVER_PORT"></a><br />SERVER_PORT</a>: <code>80</code></dt><dd></dd>
  5009. <dt><a id="SERVER_PROTOCOL"></a><br />SERVER_PROTOCOL</a>: <code>HTTP/1.1</code></dt><dd></dd>
  5010. <dt><a id="SERVER_SOFTWARE"></a><br />SERVER_SOFTWARE</a>: <code>Apache/2.0.61 (Unix) PHP/5.5 OpenSSL/0.9.7e</code></dt><dd></dd>
  5011. <dt><a id="THE_REQUEST"></a><br />THE_REQUEST</a>: <code>GET /pro/mod_rewrite/index.php?k=i HTTP/1.1</code></dt>
  5012. <dd><pre class="prettyprint lang-config">RewriteCond %{THE_REQUEST} ^(GET|POST) /.*?(s|search)=(.+) HTTP/ [NC]
  5013. RewriteRule .* https://www.askapache.com/search/%3/? [R=302,L,NE]</pre></dd>
  5014. <dt><a id="TIME"></a><br />TIME</a>: <code>20080915152142</code></dt>
  5015. <dd><pre class="prettyprint lang-config">RewriteCond %{QUERY_STRING} showtime [NC]
  5016. RewriteCond T:%{TIME}_TY:%{TIME_YEAR}_TMO:%{TIME_MON}_TWD:%{TIME_WDAY}_TD:%{TIME_DAY}_TH:%{TIME_HOUR}_TMI:%{TIME_MIN}_TS:%{TIME_SEC} ^(.*)$
  5017. RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}?time=%1 [R,L]</pre></dd>
  5018. <dt><a id="TIME_DAY"></a><br />TIME_DAY</a>: <code>15</code></dt><dd></dd>
  5019. <dt><a id="TIME_HOUR"></a><br />TIME_HOUR</a>: <code>15</code></dt><dd></dd>
  5020. <dt><a id="TIME_MIN"></a><br />TIME_MIN</a>: <code>21</code></dt><dd></dd>
  5021. <dt><a id="TIME_MON"></a><br />TIME_MON</a>: <code>09</code></dt><dd></dd>
  5022. <dt><a id="TIME_SEC"></a><br />TIME_SEC</a>: <code>42</code></dt><dd></dd>
  5023. <dt><a id="TIME_WDAY"></a><br />TIME_WDAY</a>: <code>1</code></dt><dd></dd>
  5024. <dt><a id="TIME_YEAR"></a><br />TIME_YEAR</a>: <code>2008</code></dt><dd></dd>
  5025. <dt><a id="UNIQUE_ID"></a><br />UNIQUE_ID</a>: <code>qOr5tEBvcm8AAE-VoiUAAAAQ</code></dt><dd></dd>
  5026. </dl>
  5027.  
  5028. <dl class="dl1">
  5029. <dt><a id="HTTPS"></a><br />HTTPS</a>: <code>off</code></dt>
  5030. <dd><pre class="prettyprint lang-config">RewriteCond %{HTTPS} !=on
  5031. RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]</pre></dd>
  5032. <dt><a id="SSL_CIPHER"></a><br />SSL_CIPHER</a>: <code>DHE-RSA-AES256-SHA</code></dt><dd></dd>
  5033. <dt><a id="SSL_CIPHER_ALGKEYSIZE"></a><br />SSL_CIPHER_ALGKEYSIZE</a>: <code>256</code></dt><dd></dd>
  5034. <dt><a id="SSL_CIPHER_EXPORT"></a><br />SSL_CIPHER_EXPORT</a>: <code>false</code></dt><dd></dd>
  5035. <dt><a id="SSL_CIPHER_USEKEYSIZE"></a><br />SSL_CIPHER_USEKEYSIZE</a>: <code>256</code></dt><dd></dd>
  5036. <dt><a id="SSL_CLIENT_VERIFY"></a><br />SSL_CLIENT_VERIFY</a>: <code>NONE</code></dt><dd></dd>
  5037. <dt><a id="SSL_PROTOCOL"></a><br />SSL_PROTOCOL</a>: <code>TLSv1</code></dt><dd></dd>
  5038. <dt><a id="SSL_SERVER_A_KEY"></a><br />SSL_SERVER_A_KEY</a>: <code>rsaEncryption</code></dt><dd></dd>
  5039. <dt><a id="SSL_SERVER_A_SIG"></a><br />SSL_SERVER_A_SIG</a>: <code>sha1WithRSAEncryption</code></dt><dd></dd>
  5040. <dt><a id="SSL_SERVER_CERT"></a><br />SSL_SERVER_CERT</a>: <code>-----BEGIN CERTIFICATE----- ... MIIFkTC ... -----END CERTIFICATE-----</code></dt><dd></dd>
  5041. <dt><a id="SSL_SERVER_I_DN"></a><br />SSL_SERVER_I_DN</a>: <code>/C=US/ST=Arizona/L=Scottsdale/O=Starfield Technologies, Inc./OU=http://certificates.starfieldtech.com/repository/CN=Starfield Secure Certification Authority/serialNumber=10688435</code></dt><dd></dd>
  5042. <dt><a id="SSL_SERVER_I_DN_C"></a><br />SSL_SERVER_I_DN_C</a>: <code>US</code></dt><dd></dd>
  5043. <dt><a id="SSL_SERVER_I_DN_CN"></a><br />SSL_SERVER_I_DN_CN</a>: <code>Starfield Secure Certification Authority</code></dt><dd></dd>
  5044. <dt><a id="SSL_SERVER_I_DN_L"></a><br />SSL_SERVER_I_DN_L</a>: <code>Scottsdale</code></dt><dd></dd>
  5045. <dt><a id="SSL_SERVER_I_DN_O"></a><br />SSL_SERVER_I_DN_O</a>: <code>Starfield Technologies, Inc.</code></dt><dd></dd>
  5046. <dt><a id="SSL_SERVER_I_DN_OU"></a><br />SSL_SERVER_I_DN_OU</a>: <code>http://certificates.starfieldtech.com/repository</code></dt><dd></dd>
  5047. <dt><a id="SSL_SERVER_I_DN_ST"></a><br />SSL_SERVER_I_DN_ST</a>: <code>Arizona</code></dt><dd></dd>
  5048. <dt><a id="SSL_SERVER_M_SERIAL"></a><br />SSL_SERVER_M_SERIAL</a>: <code>042840B88A2352</code></dt><dd></dd>
  5049. <dt><a id="SSL_SERVER_M_VERSION"></a><br />SSL_SERVER_M_VERSION</a>: <code>3</code></dt><dd></dd>
  5050. <dt><a id="SSL_SERVER_S_DN"></a><br />SSL_SERVER_S_DN</a>: <code>/O=www.askapache.com/OU=Domain Control Validated/CN=www.askapache.com</code></dt><dd></dd>
  5051. <dt><a id="SSL_SERVER_S_DN_CN"></a><br />SSL_SERVER_S_DN_CN</a>: <code>www.askapache.com</code></dt><dd></dd>
  5052. <dt><a id="SSL_SERVER_S_DN_O"></a><br />SSL_SERVER_S_DN_O</a>: <code>www.askapache.com</code></dt><dd></dd>
  5053. <dt><a id="SSL_SERVER_S_DN_OU"></a><br />SSL_SERVER_S_DN_OU</a>: <code>Domain Control Validated</code></dt><dd></dd>
  5054. <dt><a id="SSL_SERVER_V_END"></a><br />SSL_SERVER_V_END</a>: <code>Jul 14 16:53:43 2012 GMT</code></dt><dd></dd>
  5055. <dt><a id="SSL_SERVER_V_START"></a><br />SSL_SERVER_V_START</a>: <code>Jul 14 20:25:17 2010 GMT</code></dt><dd></dd>
  5056. <dt><a id="SSL_SESSION_ID"></a><br />SSL_SESSION_ID</a>: <code>4184083DD1C74547553018174950D88987BD7ED03CE54EBB6638539C34814376</code></dt><dd></dd>
  5057. <dt><a id="SSL_VERSION_INTERFACE"></a><br />SSL_VERSION_INTERFACE</a>: <code>mod_ssl/2.2.16</code></dt><dd></dd>
  5058. <dt><a id="SSL_VERSION_LIBRARY"></a><br />SSL_VERSION_LIBRARY</a>: <code>OpenSSL/0.9.8e-fips-rhel5</code></dt><dd></dd>
  5059. </dl>
  5060.  
  5061. <h2>Htaccess Time Cheatsheet</h2>
  5062. <pre>
  5063. #      300   5 MIN
  5064. #      600  10 MIN
  5065. #      900  15 MIN
  5066. #     1800  30 MIN
  5067. #     2700  45 MIN
  5068. #     3600   1 HR
  5069. #     7200   2 HR
  5070. #    10800   3 HR
  5071. #    14400   4 HR
  5072. #    18000   5 HR
  5073. #    36000  10 HR
  5074. #    39600  11 HR
  5075. #    43200  12 HR
  5076. #    46800  13 HR
  5077. #    50400  14 HR
  5078. #    54000  15 HR
  5079. #    86400   1 DAY
  5080. #   172800   2 DAY
  5081. #   259200   3 DAY
  5082. #   345600   4 DAY
  5083. #   432000   5 DAY
  5084. #   518400   6 DAY
  5085. #   604800   1 WEEK
  5086. #  1209600   2 WEEK
  5087. #  1814400   3 WEEK
  5088. #  2419200   4 WEEK
  5089. #  4838400   2 MONTH
  5090. #  7257600   3 MONTH
  5091. #  9676800   4 MONTH
  5092. # 12096000   5 MONTH
  5093. # 14515200   6 MONTH
  5094. # 16934400   7 MONTH
  5095. # 19353600   8 MONTH
  5096. # 21772800   9 MONTH
  5097. # 24192000  10 MONTH
  5098. # 26611200  11 MONTH
  5099. # 29030400  12 MONTH
  5100. </pre>
  5101.  
  5102.  
  5103.  
  5104.  
  5105.  
  5106.  
  5107. <h2>Mod_Rewrite Directives</h2>
  5108. <p class="cnote">For a broader mod_rewrite cheat sheet, check this <a href="http://www.addedbytes.com/apache/mod_rewrite-cheat-sheet/">printable</a> cheat sheet.</p>
  5109.  
  5110. <dl>
  5111. <dt><strong>RewriteEngine</strong></dt>
  5112. <dd><pre class="prettyprint lang-config">RewriteEngine on|off</pre> On or Off to enable or disable (default) the whole rewriting engine</dd>
  5113. <dt><strong>RewriteOptions</strong></dt>
  5114. <dd><pre class="prettyprint lang-config">RewriteOptions Options</pre> List of option strings to set</dd>
  5115. <dt><strong>RewriteBase</strong></dt>
  5116. <dd><pre class="prettyprint lang-config">RewriteBase URL-path</pre> the base URL of the per-directory context
  5117. <dt><strong>RewriteCond</strong></dt>
  5118. <dd><pre class="prettyprint lang-config">RewriteCond TestString CondPattern</pre> an input string and a to be applied regexp-pattern
  5119. <dt><strong>RewriteRule</strong></dt>
  5120. <dd><pre class="prettyprint lang-config">RewriteRule Pattern Substitution [flags]</pre> an URL-applied regexp-pattern and a substitution URL
  5121. <dt><strong>RewriteMap</strong></dt>
  5122. <dd><pre class="prettyprint lang-config">RewriteMap MapName MapType:MapSource</pre> a mapname and a filename
  5123. <dt><strong>RewriteLock</strong></dt>
  5124. <dd><pre class="prettyprint lang-config">RewriteLock file-path</pre> the filename of a lockfile used for inter-process synchronization
  5125. <dt><strong>RewriteLog</strong></dt>
  5126. <dd><pre class="prettyprint lang-config">RewriteLog file-path</pre> the filename of the rewriting logfile
  5127. <dt><strong>RewriteLogLevel</strong></dt>
  5128. <dd><pre class="prettyprint lang-config">RewriteLogLevel Level</pre> the level of the rewriting logfile verbosity (0=none, 1=std, .., 9=max)
  5129. </dl>
  5130.  
  5131.  
  5132. <h3>Rules and Conditions Processing Order</h3>
  5133. <ol>
  5134. <li>The Pattern of the <code>RewriteRule</code> (^/.*$) is checked first.</li>
  5135. <li>If the pattern matches, then the RewriteCond's are checked.</li>
  5136. <li>If the RewriteConditions also match, the <code>RewriteRule</code> is applied.</li>
  5137. </ol>
  5138.  
  5139.  
  5140. <h3>RewriteRule Flags</h3>
  5141. <dl>
  5142. <dt><abbr title="Chain">C</abbr></dt>
  5143. <dd>Using the [Chain], or [C] flag, allows you to indicate that several rules should be chained together as a single logical transation. This is usually used when a transformation is sufficiently complicated to warrant breaking into several smaller steps.</dd>
  5144. <dt><abbr title="Cookie">CO</abbr></dt>
  5145. <dd><pre>cookie|CO=Name:Value:Domain[:Lifetime[:Path]]</pre><br />
  5146. This sets a cookie on the client's browser. The cookie's name is specified by NAME and the value is VAL. The domain field is the domain of the cookie, such as '.apache.org',the optional lifetime is the lifetime of the cookie in minutes, and the optional path is the path of the cookie.</dd>
  5147. <dt><abbr title="Env">E</abbr></dt>
  5148. <dd><pre>&#039;env|E=VAR:VAL&#039; (set environment variable)</pre><br />
  5149. <pre class="prettyprint lang-config">RewriteRule (root|cmd)\.exe - [E=worm:nimda]</pre></dd>
  5150. <dt><abbr title="Forbidden">F</abbr></dt>
  5151. <dd><pre>&#039;forbidden|F&#039; (force URL to be forbidden)</pre><br /></dd>
  5152. <dt><abbr title="Gone">G</abbr></dt>
  5153. <dd><pre>&#039;gone|G&#039; (force URL to be gone)</pre><br /></dd>
  5154. <dt><abbr title="Handler">H</abbr></dt>
  5155. <dd><pre>&#039;handler|H=Content-handler&#039; (force Content handler)</pre><br /></dd>
  5156. <dt><abbr title="Last">L</abbr></dt>
  5157. <dd><pre>&#039;last|L&#039; (last rule)</pre><br /></dd>
  5158. <dt><abbr title="Next">N</abbr></dt>
  5159. <dd><pre>&#039;next|N&#039; (next round)</pre><br /></dd>
  5160. <dt><abbr title="No Case">NC</abbr></dt>
  5161. <dd><pre>&#039;nocase|NC&#039; (no case)</pre><br /></dd>
  5162. <dt><abbr title="No Escape">NE</abbr></dt>
  5163. <dd><pre>&#039;noescape|NE&#039; (no URI escaping of output)</pre><br /></dd>
  5164. <dt><abbr title="No Subrequest">NS</abbr></dt>
  5165. <dd><pre>&#039;nosubreq|NS&#039; (not for internal sub-requests)</pre><br /></dd>
  5166. <dt><abbr title="Proxy">P</abbr></dt>
  5167. <dd><pre>&#039;proxy|P&#039; (force proxy)</pre><br /></dd>
  5168. <dt><abbr title="pass through">PT</abbr></dt>
  5169. <dd><pre>&#039;passthrough|PT&#039; (pass through to next handler)</pre><br /></dd>
  5170. <dt><abbr title="Query String Append">QSA</abbr></dt>
  5171. <dd><pre>&#039;qsappend|QSA&#039; (query string append)</pre><br /></dd>
  5172. <dt><abbr title="Redirect">R</abbr></dt>
  5173. <dd><pre>&#039;redirect|R  [=code]&#039; (force redirect)</pre><br /></dd>
  5174. <dt><abbr title="Skip">S</abbr></dt>
  5175. <dd><pre>&#039;skip|S=num&#039; (skip next rule(s))</pre><br />
  5176. This flag forces the rewriting engine to skip the next num rules in sequence, if the current rule matches. Use this to make pseudo if-then-else constructs: The last rule of the then-clause becomes skip=N, where N is the number of rules in the else-clause. (This is not the same as the 'chain|C' flag!)</dd>
  5177. <dt><abbr title="Type">T</abbr></dt>
  5178. <dd><pre>&#039;type|T=MIME-type&#039; (force MIME type)</pre><br />
  5179. Force the MIME-type of the target file to be MIME-type. This can be used to set up the content-type based on some conditions. For example, the following snippet allows .php files to be displayed by mod_php if they are called with the .phps extension:</dd>
  5180. </dl>
  5181.  
  5182.  
  5183. <h3>RewriteRule Special Variables</h3>
  5184. <ol>
  5185. <li><strong>ENV_</strong></li>
  5186. <li><strong>SSL_</strong></li>
  5187. <li><strong>HTTP_</strong></li>
  5188. <li><strong>LA-U_</strong></li>
  5189. <li><strong>LA-F_</strong></li>
  5190. </ol>
  5191.  
  5192.  
  5193. <h3>RewriteCond Tests</h3>
  5194. <ul>
  5195. <li><strong>-f</strong> - FILE_EXISTS</li>
  5196. <li><strong>-s</strong> - FILE_SIZE</li>
  5197. <li><strong>-l</strong> - FILE_LINK</li>
  5198. <li><strong>-d</strong> - FILE_DIR</li>
  5199. <li><strong>-x</strong> - FILE_XBIT</li>
  5200. <li><strong>-U</strong> - LU_URL</li>
  5201. <li><strong>-F</strong> - LU_FILE</li>
  5202. <li><strong>&gt;</strong> - STR_GT</li>
  5203. <li><strong>&lt;</strong> - STR_LT</li>
  5204. <li><strong>=</strong> - STR_EQ</li>
  5205. </ul>
  5206.  
  5207.  
  5208.  
  5209.  
  5210.  
  5211.  
  5212.  
  5213. <h2>Mod_Rewrite Variables, from Source</h2>
  5214. <ul>
  5215. <li>API_VERSION - <code>"%d:%d",MODULE_MAGIC_NUMBER_MAJOR,MODULE_MAGIC_NUMBER_MINOR)</code></li>
  5216. <li>APR_FINFO_USER</li>
  5217. <li>AUTH_TYPE - <code>ap_auth_type</code></li>
  5218. <li>DOCUMENT_ROOT - <code>ap_document_root(r)</code></li>
  5219. <li>HTTP_ACCEPT - <code>lookup_header("Accept", ctx)</code></li>
  5220. <li>HTTP_COOKIE - <code>lookup_header("Cookie", ctx)</code></li>
  5221. <li>HTTP_FORWARDED - <code>lookup_header("Forwarded", ctx)</code></li>
  5222. <li>HTTP_HOST - <code>lookup_header("Host", ctx)</code></li>
  5223. <li>HTTP_PROXY_CONNECTION - <code>lookup_header("Proxy-Connection", ctx)</code></li>
  5224. <li>HTTP_REFERER - <code>lookup_header("Referer", ctx)</code></li>
  5225. <li>HTTPS - <code>flag ? "on" : "off"</code></li>
  5226. <li>HTTP_USER_AGENT - <code>lookup_header("User-Agent", ctx)</code></li>
  5227. <li>IS_SUBREQ - <code>(main ? "true" : "false")</code></li>
  5228. <li>PATH_INFO - <code>path_info</code></li>
  5229. <li>QUERY_STRING - <code>args</code></li>
  5230. <li>REMOTE_ADDR - <code>connection-&gt;remote_ip</code></li>
  5231. <li>REMOTE_HOST</li>
  5232. <li>REMOTE_IDENT - <code>ap_get_remote_logname(r)</code></li>
  5233. <li>REMOTE_NAME</li>
  5234. <li>REMOTE_PORT - <code>r-&gt;connection-&gt;remote_addr-&gt;port</code></li>
  5235. <li>REMOTE_USER - <code>user</code></li>
  5236. <li>REQUEST_FILENAME - <code>same as script_filename</code></li>
  5237. <li>REQUEST_METHOD - <code>method</code></li>
  5238. <li>REQUEST_URI - <code>uri</code></li>
  5239. <li>SCRIPT_FILENAME - <code>same as request_filename</code></li>
  5240. <li>SCRIPT_GROUP - <code>unknown</code></li>
  5241. <li>SCRIPT_USER - <code>unknown</code></li>
  5242. <li>SERVER_ADDR - <code>connection-&gt;local_ip</code></li>
  5243. <li>SERVER_ADMIN - <code>server-&gt;server_admin</code></li>
  5244. <li>SERVER_NAME - <code>ap_get_server_name(r)</code></li>
  5245. <li>SERVER_PORT - <code>ap_get_server_port(r)</code></li>
  5246. <li>SERVER_PROTOCOL - <code>protocol</code></li>
  5247. <li>SERVER_SOFTWARE - <code>ap_get_server_banner()</code></li>
  5248. <li>THE_REQUEST - <code>the_request</code></li>
  5249. <li>TIME - <code>%04d%02d%02d%02d%02d%02d</code></li>
  5250. <li>TIME_DAY</li>
  5251. <li>TIME_HOUR</li>
  5252. <li>TIME_MIN</li>
  5253. <li>TIME_MON</li>
  5254. <li>TIME_SEC</li>
  5255. <li>TIME_WDAY</li>
  5256. <li>TIME_YEAR</li>
  5257. </ul>
  5258.  
  5259. <h3>Special Rewrite Redirects</h3>
  5260. <ol>
  5261. <li>"permanent" - <code>HTTP_MOVED_PERMANENTLY</code></li>
  5262. <li>"temp" - <code>HTTP_MOVED_TEMPORARILY</code></li>
  5263. <li>"seeother" - <code>HTTP_SEE_OTHER</code></li>
  5264. <li>digit</li>
  5265. </ol>
  5266.  
  5267.  
  5268. <h3>Protocols Recognized by Mod_Rewrite</h3>
  5269. <ol>
  5270. <li><strong>ajp://</strong> - Apache JServ Protocol</li>
  5271. <li><strong>balancer://</strong> - Apache Load Balancer</li>
  5272. <li><strong>ftp://</strong> - File Transfer Protocol</li>
  5273. <li><strong>gopher://</strong> - Gopher (protocol)</li>
  5274. <li><strong>http://</strong> - Hypertext Transfer Protocol</li>
  5275. <li><strong>https://</strong> - Hypertext Transfer Protocol Secure</li>
  5276. <li><strong>ldap://</strong> - Lightweight Directory Access Protocol</li>
  5277. <li><strong>mailto:</strong> - The mailto URI scheme</li>
  5278. <li><strong>news:</strong> - News Protocol</li>
  5279. <li><strong>nntp://</strong> - Network News Transfer Protocol</li>
  5280. </ol>
  5281.  
  5282.  
  5283. <h3>Mod_Rewrite Terms and Definitions</h3>
  5284. <dl>
  5285. <dt>pattern</dt><dd>the RegExp pattern string</dd>
  5286. <dt>regexp<dt><dd>the RegExp pattern compilation</dd>
  5287. <dt>flags</dt><dd>Flags which control the substitution</dd>
  5288. <dt>forced_mimetype</dt><dd>forced MIME type of substitution</dd>
  5289. <dt>forced_handler</dt><dd>forced content handler of subst.</dd>
  5290. <dt>forced_responsecode</dt><dd>forced HTTP response status</dd>
  5291. <dt>env</dt><dd>added environment variables</dd>
  5292. <dt>cookie</dt><dd>added cookies</dd>
  5293. <dt>skip</dt><dd>number of next rules to skip</dd>
  5294. <dt>state</dt><dd>the RewriteEngine state</dd>
  5295. <dt>options</dt><dd>the RewriteOption state</dd>
  5296. <dt>rewritelogfile</dt><dd>the RewriteLog filename</dd>
  5297. <dt>rewritelogfp</dt><dd>the RewriteLog open filepointer</dd>
  5298. <dt>rewritelog:  level</dt><dd>the RewriteLog level of verbosity</dd>
  5299. <dt>rewritemaps</dt><dd>the RewriteMap entries</dd>
  5300. <dt>rewriteconds</dt><dd>the RewriteCond entries (temp.)</dd>
  5301. <dt>rewriterules</dt><dd>the RewriteRule entries</dd>
  5302. <dt>directory</dt><dd>the directory where it applies</dd>
  5303. <dt>baseurl</dt><dd>the base-URL where it applies</dd>
  5304. </dl>
  5305.  
  5306.  
  5307. <h2>REGEX Rewrite Guides</h2>
  5308. <ul>
  5309. <li><a href="http://etext.lib.virginia.edu/services/helpsheets/unix/regex.html" title="Stephen Ramsay - Electronic Text Center - University of Virginia ">Using Regular Expressions</a></li>
  5310. <li><a href="http://check-these.info/mod_rewrite-basic.html">RewriteRule (mod_rewrite) guide</a></li>
  5311. </ul>
  5312.  
  5313.  
  5314.  
  5315.  
  5316.  
  5317.  
  5318.  
  5319.  
  5320. <h2>URL Rewriting Module</h2>
  5321. <blockquote cite="http://apache.askapache.com/httpd/httpd-2.2.8/modules/mappers/mod_rewrite.c">
  5322. <p>This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly.</p>
  5323. <p>It supports an unlimited number of additional rule conditions (which can operate on a lot of variables, even on HTTP headers) for granular matching and even external database lookups (either via plain text tables, DBM hash files or even external processes) for advanced URL substitution.</p>
  5324. <p>It operates on the full URLs (including the PATH_INFO part) both in per-server context (httpd.conf) and per-dir context (.htaccess) and even  can generate QUERY_STRING parts on result.  The rewriting result finally can lead to internal subprocessing, external request redirection or even to internal proxy throughput.</p>
  5325. <p>This module was originally written in April 1996 and gifted exclusively to the The Apache Software Foundation in July 1997 by</p>
  5326. <address class="vcard">
  5327. <a class="fn url" href="http://engelschall.com/" title="Ralf S. Engelschall">Ralf S. Engelschall</a>
  5328. <a class="fn email" href="http://engelschall.com/contact.php">rse [at] engenschall.com</a>
  5329. </address>
  5330. </blockquote>
  5331.  
  5332. <h2>Mod_Rewrite Errors</h2>
  5333. <ul style="font-size:10px;">
  5334. <li><code>Options FollowSymLinks or SymLinksIfOwnerMatch is off  which implies that RewriteRule directive is forbidden:  %s</code></li>
  5335. <li><code>RewriteCond: bad argument line</code></li>
  5336. <li><code>RewriteCond: NoCase option for non-regex pattern %s  is not supported and will be ignored.</code></li>
  5337. <li><code>RewriteCond: cannot compile regular  expression</code></li>
  5338. <li><code>RewriteRule: invalid HTTP  response code %s for  flag R</code></li>
  5339. <li><code>RewriteRule: unknown flag</code></li>
  5340. <li><code>RewriteRule: cannot compile regular expression</code></li>
  5341. <li><code>RewriteOptions: MaxRedirects option has been  removed in favor of the global  LimitInternalRecursion directive and will be  ignored.</code></li>
  5342. <li><code>RewriteOptions: unknown option</code></li>
  5343. <li><code>RewriteMap: bad path to txt map:</code></li>
  5344. <li><code>RewriteMap: bad path to rnd map:</code></li>
  5345. <li><code>RewriteMap: bad map:</code></li>
  5346. <li><code>RewriteMap: bad path to dbm map:</code></li>
  5347. <li><code>RewriteMap: dbm type</code></li>
  5348. <li><code>RewriteMap: bad path to prg map:</code></li>
  5349. <li><code>RewriteMap: internal map not found:</code></li>
  5350. <li><code>RewriteMap: bad path to txt map:</code></li>
  5351. <li><code>RewriteMap: file for map not found:</code></li>
  5352. <li><code>Invalid RewriteLock path</code></li>
  5353. <li><code>RewriteBase: only valid in per-directory config files</code></li>
  5354. <li><code>RewriteBase: empty URL not allowed</code></li>
  5355. <li><code>RewriteBase: argument is not a valid URL</code></li>
  5356. <li><code>RewriteCond: bad flag delimiters</code></li>
  5357. <li><code>RewriteCond: unknown flag</code></li>
  5358. <li><code>RewriteLog and RewriteLogLevel are not supported by this build of mod_rewrite because it was compiled using the -DREWRITELOG_DISABLED compiler option. You have to recompile mod_rewrite WITHOUT this option in order to use the rewrite log.</code></li>
  5359. <li><code>mod_rewrite: Invalid RewriteLog  path %s</code></li>
  5360. <li><code>mod_rewrite: could not open reliable pipe  to RewriteLog filter %s</code></li>
  5361. <li><code>mod_rewrite: Invalid RewriteLog  path %s</code></li>
  5362. <li><code>mod_rewrite: could not open RewriteLog  file %s</code></li>
  5363. <li><code>mod_rewrite: Running external rewrite maps  without defining a RewriteLock is DANGEROUS!</code></li>
  5364. <li><code>mod_rewrite: could not start RewriteMap  program %s</code></li>
  5365. <li><code>mod_rewrite: cant access text RewriteMap file %s</code></li>
  5366. <li><code>mod_rewrite: cant access DBM RewriteMap file %s</code></li>
  5367. <li><code>mod_rewrite: Parent could not create RewriteLock  file %s</code></li>
  5368. <li><code>mod_rewrite: Parent could not set permissions  on RewriteLock check User and Group directives</code></li>
  5369. <li><code>mod_rewrite: could not create rewrite_log_lock</code></li>
  5370. <li><code>mod_rewrite: Could not set permissions on  rewrite_log_lock check User and Group directives</code></li>
  5371. <li><code>mod_rewrite: could not init rewrite_mapr_lock_acquire  in child</code></li>
  5372. <li><code>mod_rewrite: could not init rewrite log lock in child</code></li>
  5373. <li><code>mod_rewrite: could not init map cache in child</code></li>
  5374. <li><code>split uri=%s -&gt; uri=%s, args=%s</code></li>
  5375. <li><code>reduce %s -&gt; %s</code></li>
  5376. <li><code>strip matching prefix: %s -&gt; %s</code></li>
  5377. <li><code>add subst prefix: %s -&gt; %s</code></li>
  5378. <li><code>cant open RewriteMap file, see error log</code></li>
  5379. <li><code>cache lookup FAILED, forcing new map lookup</code></li>
  5380. <li><code>map lookup FAILED: map=%s[txt] key=%s</code></li>
  5381. <li><code>map lookup OK: map=%s[txt] key=%s -&gt; val=%s</code></li>
  5382. <li><code>cache lookup OK: map=%s[txt] key=%s -&gt; val=%s</code></li>
  5383. <li><code>randomly chosen the subvalue `%s</code></li>
  5384. <li><code>cant open DBM RewriteMap file, see error log</code></li>
  5385. <li><code>cache lookup FAILED, forcing new map lookup</code></li>
  5386. <li><code>map lookup FAILED: map=%s[dbm] key=%s</code></li>
  5387. <li><code>map lookup OK: map=%s[dbm] key=%s -&gt;  val=%s</code></li>
  5388. <li><code>cache lookup OK: map=%s[dbm] key=%s -&gt; val=%s</code></li>
  5389. <li><code>map lookup FAILED: map=%s key=%s</code></li>
  5390. <li><code>map lookup OK: map=%s key=%s -&gt; val=%s</code></li>
  5391. <li><code>map lookup FAILED: map=%s key=%s</code></li>
  5392. <li><code>map lookup OK: map=%s key=%s -&gt; val=%s</code></li>
  5393. <li><code>lookahead: path=%s var=%s  -&gt; val=%s</code></li>
  5394. <li><code>lookahead: path=%s var=%s  -&gt; val=%s</code></li>
  5395. <li><code>RESULT=%s</code></li>
  5396. <li><code>escaping backreference %s to %s</code></li>
  5397. <li><code>setting env variable %s to %s</code></li>
  5398. <li><code>setting cookie %s, cookie</code></li>
  5399. <li><code>skipping already set cookie %s</code></li>
  5400. <li><code>RewriteCond URI (-U) check:  path=%s -&gt; status=%d</code></li>
  5401. <li><code>RewriteCond file (-F) check: path=%s  -&gt; file=%s status=%d</code></li>
  5402. <li><code>RewriteCond: input=%s pattern=%s%s%s%s  =&gt; %s</code></li>
  5403. <li><code>remember %s to have MIME-type  %s</code></li>
  5404. <li><code>remember %s to have  Content-handler %s</code></li>
  5405. <li><code>add path info postfix: %s -&gt; %s%s</code></li>
  5406. <li><code>strip per-dir prefix: %s -&gt; %s</code></li>
  5407. <li><code>applying pattern %s to uri %s</code></li>
  5408. <li><code>rewrite %s -&gt; %s, ctx-&gt;uri</code></li>
  5409. <li><code>forcing responsecode %d for %s</code></li>
  5410. <li><code>add per-dir prefix: %s -&gt; %s%s</code></li>
  5411. <li><code>forcing proxy-throughput with %s</code></li>
  5412. <li><code>explicitly forcing redirect with %s</code></li>
  5413. <li><code>implicitly forcing redirect (rc=%d)  with %s</code></li>
  5414. <li><code>forcing %s to get passed through  to next API URI-to-filename handler</code></li>
  5415. <li><code>init rewrite engine with requested uri %s</code></li>
  5416. <li><code>go-ahead with proxy request  %s [OK]</code></li>
  5417. <li><code>dconf-&gt;directory,trying to replace prefix %s with %s</code></li>
  5418. <li><code>escaping %s for redirect</code></li>
  5419. <li><code>redirect to %s [REDIRECT/%d]</code></li>
  5420. <li><code>initial URL equal rewritten  URL: %s [IGNORING REWRITE]</code></li>
  5421. <li><code>dconf-&gt;directory, trying to replace prefix  %s with %s</code></li>
  5422. <li><code>strip document_root  prefix: %s -&gt; %s</code></li>
  5423. <li><code>internal redirect with %s  [INTERNAL REDIRECT]</code></li>
  5424. <li><code>pass through %s</code></li>
  5425. <li><code>force filename %s to have MIME-type %s</code></li>
  5426. <li><code>force filename %s to have the  Content-handler %s,</code></li>
  5427. <li><code>init rewrite engine with requested uri %s</code></li>
  5428. <li><code>init rewrite engine with passed filename  %s. Original uri = %s</code></li>
  5429. <li><code>uri already rewritten. Status %s, Uri %s,   %s</code></li>
  5430. <li><code>attempt to make remote request from mod_rewrite  without proxy enabled: %s</code></li>
  5431. <li><code>go-ahead with proxy request %s [OK]</code></li>
  5432. <li><code>escaping %s for redirect</code></li>
  5433. <li><code>redirect to %s [REDIRECT/%d]</code></li>
  5434. <li><code>local path result: %s</code></li>
  5435. <li><code>prefixing with document_root of %s  FAILED</code></li>
  5436. <li><code>prefixed with document_root to %s</code></li>
  5437. <li><code>go-ahead with %s [OK]</code></li>
  5438. <li><code>pass through %s</code></li>
  5439. </ul><p><a rel="nofollow" href="https://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet/">Mod_Rewrite Variables Cheatsheet</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  5440. ]]></content:encoded>
  5441. <wfw:commentRss>https://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet/feed/</wfw:commentRss>
  5442. <slash:comments>25</slash:comments>
  5443. </item>
  5444. <item>
  5445. <title>Htaccess Rewrites &#8211; Rewrite Tricks and Tips</title>
  5446. <link>https://www.askapache.com/htaccess/modrewrite-tips-tricks/</link>
  5447. <comments>https://www.askapache.com/htaccess/modrewrite-tips-tricks/#comments</comments>
  5448. <pubDate>Tue, 01 Sep 2015 14:05:00 +0000</pubDate>
  5449. <dc:creator><![CDATA[AskApache]]></dc:creator>
  5450. <category><![CDATA[Htaccess]]></category>
  5451. <category><![CDATA[Apache HTTP Server]]></category>
  5452. <category><![CDATA[Redirect]]></category>
  5453. <category><![CDATA[rewrite]]></category>
  5454. <category><![CDATA[RewriteBase]]></category>
  5455. <category><![CDATA[RewriteCond]]></category>
  5456. <category><![CDATA[RewriteEngine]]></category>
  5457. <category><![CDATA[RewriteLock]]></category>
  5458. <category><![CDATA[RewriteLog]]></category>
  5459. <category><![CDATA[RewriteMap]]></category>
  5460. <category><![CDATA[RewriteOptions]]></category>
  5461. <category><![CDATA[RewriteRule]]></category>
  5462.  
  5463. <guid isPermaLink="false">https://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks/</guid>
  5464. <description><![CDATA[<p><strong>htaccess rewrite</strong> / Mod_Rewrite Tips and Tricks is as glamorous as it sounds!  htaccess rewrite mod_rewrite is just possibly one of the most useful Apache modules and features.  The ability to rewrite requests internally as well as externally is extremely powerful.</p>
  5465. <p><a class="hs hs13" href="https://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks/"></a></p>
  5466. <p><a rel="nofollow" href="https://www.askapache.com/htaccess/modrewrite-tips-tricks/">Htaccess Rewrites &#8211; Rewrite Tricks and Tips</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  5467. ]]></description>
  5468. <content:encoded><![CDATA[<p><a class="hs hs13" href="https://www.askapache.com/pub/servers/mod_rewrite.c.html"></a><br /><strong>Htaccess Rewrites</strong> are enabled by using the Apache module mod_rewrite, which is one of the most powerful Apache modules and features availale.  <a href="https://www.askapache.com/htaccess/">Htaccess</a> Rewrites through mod_rewrite provide the special ability to <strong>Rewrite requests internally</strong> as well as <em>Redirect request externally</em>.<br class="C" /></p>
  5469.  
  5470.  
  5471. <p>When the url in your browser's location bar stays the same for a request it is an internal rewrite, when the url changes an external redirection is taking place.  This is one of the first, and one of the biggest mental-blocks people have when learning about mod_rewrite...  But I have a secret weapon for you to use, a new discovery from years of research that makes learning mod_rewrite drastically quicker and easier.  It truly does or I wouldn't be saying so in the introduction of this article.</p>
  5472.  
  5473. <blockquote><p>Despite the tons of examples and docs, <strong>mod_rewrite is voodoo</strong>.
  5474. Damned cool voodoo, but still voodoo.<br />-- <cite>Brian Moore</cite></p></blockquote>
  5475.  
  5476. <p class="anote"><strong>Note:</strong>  After years of fighting to learn my way through rewriting urls with mod_rewrite, I finally had a breakthrough and found a way to outsmart the difficulty of mod_rewrite that I just couldn't seem to master.  The <a href="https://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet/">Mod_Rewrite RewriteCond/RewriteRule Variable Value Cheatsheet</a> is the one-of-a-kind tool that changed the game for me and made mod_rewriting no-harder than anything else.</p>
  5477.  
  5478. <p>So keep that mod_rewrite reference bookmarked and you will be able to figure out any RewriteRule or RewriteCond, an amazing feat considering it took me a LONG time to figure this stuff out on my own.  But that was before <a href="https://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial/">the craziness</a>, one of the most challenging and productive .htaccess experiments I've done... An experiment so <strong>ILL</strong> it's sick like a diamond disease on your wrist! $$$.  That mod_rewrite experiment/tutorial was the culmination of many different advanced mod_rewrite experiments I had done in the past and included most of my very best .htaccess tricks.  With the cheatsheet it's no longer Voodoo.. Its just what you do.  Now lets dig in!</p>
  5479.  
  5480.  
  5481. <p>If you really want to take a look, check out the <a href="https://www.askapache.com/pub/servers/mod_rewrite.c.html">mod_rewrite.c</a> and <a href="https://www.askapache.com/pub/servers/mod_rewrite.h.html">mod_rewrite.h</a> files.</p>
  5482.  
  5483. <p>Be aware that mod_rewrite (<em>RewriteRule, RewriteBase, and RewriteCond</em>) code is executed for each and every HTTP request that accesses a file in or below the directory where the code resides, so it's always good to limit the code to certain circumstances if readily identifiable.</p>
  5484. <p><strong>For example</strong>, to limit the next 5 RewriteRules to only be applied to .html and .php files, you can use the following code, which tests if the url does not end in .html or .php and if it doesn't, it will skip the next 5 RewriteRules.</p><hr />
  5485. <pre class="prettyprint lang-config">
  5486. RewriteRule !\.(html|php)$ - [S=5]
  5487. RewriteRule ^.*-(vf12|vf13|vf5|vf35|vf1|vf10|vf33|vf8).+$ - [S=1]
  5488. </pre>
  5489.  
  5490. <h2><a href="#default-mod-rewrite-hint" name="default-mod-rewrite-hint" id="default-mod-rewrite-hint" title="Mostly .htaccess rewrite examples should begin with:" class="acd">.htaccess rewrite examples should begin with:</a></h2>
  5491. <pre class="prettyprint lang-config">
  5492. Options +FollowSymLinks
  5493.  
  5494. RewriteEngine On
  5495. RewriteBase /
  5496. </pre>
  5497.  
  5498.  
  5499. <h2><a href="#require-the-www-in-htaccess" name="require-the-www-in-htaccess" id="require-the-www-in-htaccess" title="Require the www" class="acd">Require the www</a></h2>
  5500. <pre class="prettyprint lang-config">
  5501. Options +FollowSymLinks
  5502. RewriteEngine On
  5503. RewriteBase /
  5504. RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
  5505. RewriteRule ^(.*)$ https://www.askapache.com/$1 [R=301,L]
  5506. </pre>
  5507.  
  5508.  
  5509. <h2>Loop Stopping Code</h2>
  5510. <p>Sometimes your rewrites cause infinite loops, stop it with one of these rewrite code snippets.</p>
  5511. <pre class="prettyprint lang-config">
  5512. RewriteCond %{REQUEST_URI} ^/(stats/|missing\.html|failed_auth\.html|error/).* [NC]
  5513. RewriteRule .* - [L]
  5514.  
  5515. RewriteCond %{ENV:REDIRECT_STATUS} 200
  5516. RewriteRule .* - [L]
  5517. </pre>
  5518.  
  5519. <h2>Cache-Friendly File Names</h2>
  5520. <p>This is probably my favorite, and I use it on every site I work on.  It allows me to update my javascript and css files in my visitors cache's simply by naming them differently in the html, on the server they stay the same name.  This rewrites all files for <code>/zap/j/anything-anynumber.js to /zap/j/anything.js and /zap/c/anything-anynumber.css to /zap/c/anything.css</code></p>
  5521. <pre class="prettyprint lang-config">
  5522. RewriteRule ^zap/(j|c)/([a-z]+)-([0-9]+)\.(js|css)$ /zap/$1/$2.$4 [L]
  5523. </pre>
  5524.  
  5525.  
  5526.  
  5527.  
  5528. <h2>SEO friendly link for non-flash browsers</h2>
  5529. <p>When you use flash on your site and you properly supply a link to download flash that shows up for non-flash aware browsers, it is nice to use a shortcut to keep your code clean and your external links to a minimum.  This code allows me to link to <code>site.com/getflash/</code> for non-flash aware browsers.</p>
  5530. <pre class="prettyprint lang-config">
  5531. RewriteRule ^getflash/?$ http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash [NC,L,R=307]
  5532. </pre>
  5533.  
  5534. <h2>Removing the Query_String</h2>
  5535. <p>On many sites, the page will be displayed for both page.html and page.html?anything=anything, which hurts your SEO with duplicate content.  An easy way to fix this issue is to redirect external requests containing a query string to the same uri without the query_string.</p>
  5536. <pre class="prettyprint lang-config">
  5537. RewriteCond %{THE_REQUEST} ^[A-Z]+ /.*\ HTTP
  5538. RewriteCond %{QUERY_STRING} !^$
  5539. RewriteRule .* https://www.askapache.com%{REQUEST_URI}? [R=301,L]
  5540. </pre>
  5541.  
  5542.  
  5543. <h2>Sending requests to a php script</h2>
  5544. <p>This .htaccess rewrite example invisibly rewrites requests for all Adobe pdf files to be handled by <code>/cgi-bin/pdf-script.php</code></p>
  5545. <pre class="prettyprint lang-config">
  5546. RewriteRule ^(.+)\.pdf$  /cgi-bin/pdf-script.php?file=$1.pdf [L,NC,QSA]
  5547. </pre>
  5548.  
  5549.  
  5550. <h2>Setting the language variable based on Client</h2>
  5551. <p>For sites using multiviews or with multiple language capabilities, it is nice to be able to send the correct language automatically based on the clients preferred language.</p>
  5552. <pre class="prettyprint lang-config">
  5553. RewriteCond %{HTTP:Accept-Language} ^.*(de|es|fr|it|ja|ru|en).*$ [NC]
  5554. RewriteRule ^(.*)$ - [env=prefer-language:%1]
  5555. </pre>
  5556.  
  5557.  
  5558.  
  5559. <h2>Deny Access To Everyone Except PHP fopen</h2>
  5560. <p>This allows access to all files by php fopen, but denies anyone else.</p>
  5561. <pre class="prettyprint lang-config">
  5562. RewriteEngine On
  5563. RewriteBase /
  5564. RewriteCond %{THE_REQUEST} ^.+$ [NC]
  5565. RewriteRule .* - [F,L]
  5566. </pre>
  5567.  
  5568.  
  5569. <p class="cnote">If you are looking for ways to block or deny specific requests/visitors, then you should definately read <a href="http://perishablepress.com/press/2009/02/03/eight-ways-to-blacklist-with-apaches-mod_rewrite/" title="Eight Ways to Blacklist with Apache’s mod_rewrite">Blacklist with mod_rewrite</a>.  I give it a 10/10</p>
  5570.  
  5571.  
  5572. <h2>Deny access to anything in a subfolder except php fopen</h2>
  5573. <p>This can be very handy if you want to serve media files or special downloads but only through a php proxy script.</p>
  5574. <pre class="prettyprint lang-config">
  5575. RewriteEngine On
  5576. RewriteBase /
  5577. RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+)/.* HTTP [NC]
  5578. RewriteRule .* - [F,L]
  5579. </pre>
  5580.  
  5581.  
  5582.  
  5583.  
  5584.  
  5585. <h2><a href="#require-no-www-in-htaccess" name="require-no-www-in-htaccess" id="require-no-www-in-htaccess" title="Require no www" class="acd">Require no www</a></h2>
  5586. <pre class="prettyprint lang-config">
  5587. Options +FollowSymLinks
  5588. RewriteEngine On
  5589. RewriteBase /
  5590. RewriteCond %{HTTP_HOST} !^askapache\.com$ [NC]
  5591. RewriteRule ^(.*)$ http://askapache.com/$1 [R=301,L]
  5592. </pre>
  5593.  
  5594.  
  5595. <h2><a href="#check-for-key-in-query-string" name="check-for-key-in-query-string" id="check-for-key-in-query-string" title="Search for a key in the query string" class="acd">Check for a key in QUERY_STRING</a></h2>
  5596. <p>Uses a <a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritecond" title="RewriteCond Directive Use in htaccess">RewriteCond</a> Directive to check QUERY_STRING for passkey, if it doesn't find it it redirects all requests for anything in the /logged-in/ directory to the /login.php script.</p>
  5597. <pre class="prettyprint lang-config">
  5598. RewriteEngine On
  5599. RewriteBase /
  5600. RewriteCond %{QUERY_STRING} !passkey
  5601. RewriteRule ^/logged-in/(.*)$ /login.php [L]
  5602. </pre>
  5603.  
  5604.  
  5605. <h2><a href="#delete-query-string" name="delete-query-string" id="delete-query-string" title="Remove the query string from url" class="acd">Removes the QUERY_STRING from the URL</a></h2>
  5606. <p>If the QUERY_STRING has any value at all besides blank than the<code>?</code>at the end of /login.php? tells mod_rewrite to remove the QUERY_STRING from login.php and redirect.</p>
  5607. <pre class="prettyprint lang-config">
  5608. RewriteEngine On
  5609. RewriteBase /
  5610. RewriteCond %{QUERY_STRING} .
  5611. RewriteRule ^login\.php /login.php? [L]
  5612. </pre>
  5613.  
  5614.  
  5615. <h2><a href="#fix-infinite-loop-redirects" name="fix-infinite-loop-redirects" id="fix-infinite-loop-redirects" title="Fix for infinite loops" class="acd">Fix for infinite loops</a></h2>
  5616. <p>An error message related to this is<code>Request exceeded the limit of 10 internal redirects due to probable configuration error. Use &#039;LimitInternalRecursion&#039; to increase the limit if necessary. Use &#039;LogLevel debug&#039; to get a backtrace.</code>or you may see<code>Request exceeded the limit</code>,<code>probable configuration error</code>,<code>Use &#039;LogLevel debug&#039; to get a backtrace</code>, or<code>Use &#039;LimitInternalRecursion&#039; to increase the limit if necessary</code></p>
  5617. <pre class="prettyprint lang-config">
  5618. RewriteCond %{ENV:REDIRECT_STATUS} 200
  5619. RewriteRule .* - [L]
  5620. </pre>
  5621.  
  5622.  
  5623. <h2><a href="#external-redirect-php-files-to-html" name="external-redirect-php-files-to-html" id="external-redirect-php-files-to-html" title="External Redirect .php files to .html files (SEO friendly)" class="acd">External Redirect .php files to .html files (SEO friendly)</a></h2>
  5624. <pre class="prettyprint lang-config">
  5625. RewriteRule ^(.*)\.php$ /$1.html [R=301,L]
  5626. </pre>
  5627.  
  5628.  
  5629. <h2><a href="#internal-redirect-php-files-to-html" name="internal-redirect-php-files-to-html" id="internal-redirect-php-files-to-html" title="Internal Redirect .php files to .html files (SEO friendly)" class="acd">Internal Redirect .php files to .html files (SEO friendly)</a></h2>
  5630. <p>Redirects all files that end in .html to be served from filename.php  so it looks like all your pages are .html but really they are .php</p>
  5631. <pre class="prettyprint lang-config">
  5632. RewriteRule ^(.*)\.html$ $1.php [R=301,L]
  5633. </pre>
  5634.  
  5635.  
  5636. <h2><a href="#time-based-access" name="time-based-access" id="time-based-access" title="block access to files during certain hours of the day" class="acd">block access to files during certain hours of the day</a></h2>
  5637. <pre class="prettyprint lang-config">
  5638. Options +FollowSymLinks
  5639. RewriteEngine On
  5640. RewriteBase /
  5641. # If the hour is 16 (4 PM) Then deny all access
  5642. RewriteCond %{TIME_HOUR} ^16$
  5643. RewriteRule ^.*$ - [F,L]
  5644. </pre>
  5645.  
  5646.  
  5647. <h2><a href="#convert-underscore-hyphen" name="convert-underscore-hyphen" id="convert-underscore-hyphen" title="Change underscores to hyphens for SEO URL" class="acd">Rewrite underscores to hyphens for SEO URL</a></h2>
  5648. <p>Converts all underscores "_" in urls to hyphens "-" for SEO benefits...  See the <a href="https://www.askapache.com/htaccess/rewrite-underscores-to-hyphens-for-seo-url/">full article</a> for more info.</p>
  5649. <pre class="prettyprint lang-config">
  5650. Options +FollowSymLinks
  5651. RewriteEngine On
  5652. RewriteBase /
  5653.  
  5654. RewriteRule !\.(html|php)$ - [S=4]
  5655. RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes]
  5656. RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes]
  5657. RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes]
  5658. RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes]
  5659.  
  5660. RewriteCond %{ENV:uscor} ^Yes$
  5661. RewriteRule (.*) http://d.com/$1 [R=301,L]
  5662. </pre>
  5663.  
  5664.  
  5665. <h2><a href="#require-www-no-hardcoding" name="require-www-no-hardcoding" id="require-www-no-hardcoding" title="Require the www without hardcoding" class="acd">Require the www without hardcoding</a></h2>
  5666. <pre class="prettyprint lang-config">
  5667. Options +FollowSymLinks
  5668. RewriteEngine On
  5669. RewriteBase /
  5670. RewriteCond %{HTTP_HOST} !^www\.[a-z-]+\.[a-z]{2,6} [NC]
  5671. RewriteCond %{HTTP_HOST} ([a-z-]+\.[a-z]{2,6})$     [NC]
  5672. RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
  5673. </pre>
  5674.  
  5675.  
  5676. <h2><a href="#require-no-subdomain-1" name="require-no-subdomain-1" id="require-no-subdomain-1" title="Require no subdomain" class="acd">Require no subdomain</a></h2>
  5677. <pre class="prettyprint lang-config">
  5678. RewriteEngine On
  5679. RewriteBase /
  5680. RewriteCond %{HTTP_HOST} \.([a-z-]+\.[a-z]{2,6})$ [NC]
  5681. RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
  5682. </pre>
  5683.  
  5684.  
  5685. <h2><a href="#require-no-subdomain-2" name="require-no-subdomain-2" id="require-no-subdomain-2" title="Require no subdomain" class="acd">Require no subdomain</a></h2>
  5686. <pre class="prettyprint lang-config">
  5687. RewriteEngine On
  5688. RewriteBase /
  5689. RewriteCond %{HTTP_HOST} \.([^\.]+\.[^.0-9]+)$
  5690. RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  5691. </pre>
  5692.  
  5693.  
  5694. <h2><a href="#redirect-wordpress-feed" name="redirect-wordpress-feed" id="redirect-wordpress-feed" title="Redirecting Wordpress Feeds to Feedburner" class="acd">Redirecting Wordpress Feeds to Feedburner</a></h2>
  5695. <p>Full article:<a href="https://www.askapache.com/htaccess/redirecting-wordpress-feeds-to-feedburner/" title="Redirecting Wordpress Feeds to Feedburner">Redirecting Wordpress Feeds to Feedburner</a></p>
  5696. <pre class="prettyprint lang-config">
  5697. RewriteEngine On
  5698. RewriteBase /
  5699. RewriteCond %{REQUEST_URI} ^/feed\.gif$
  5700. RewriteRule .* - [L]
  5701.  
  5702. RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]
  5703. RewriteRule ^feed/?.*$ http://feeds.feedburner.com/apache/htaccess [L,R=302]
  5704.  
  5705. RewriteCond %{REQUEST_FILENAME} !-f
  5706. RewriteCond %{REQUEST_FILENAME} !-d
  5707. RewriteRule . /index.php [L]
  5708. </pre>
  5709.  
  5710.  
  5711. <h2><a href="#only-allow-get-and-put-requests" name="only-allow-get-and-put-requests" id="only-allow-get-and-put-requests" title="Only allow GET and PUT request methods" class="acd">Only allow GET and PUT Request Methods</a></h2>
  5712. <p>Article: <a class="acd" href="https://www.askapache.com/htaccess/apache-status-code-headers-errordocument/#http-methods-recognized" title="List of Apache Recognized Request Methods">Request Methods</a></p>
  5713. <pre class="prettyprint lang-config">
  5714. RewriteEngine On
  5715. RewriteBase /
  5716. RewriteCond %{REQUEST_METHOD} !^(GET|PUT)
  5717. RewriteRule .* - [F]
  5718. </pre>
  5719.  
  5720.  
  5721. <h2><a href="#prevent-hotlinking" name="prevent-hotlinking" id="prevent-hotlinking" title="Prevent Files image/file hotlinking and bandwidth stealing" class="acd">Prevent Files image/file hotlinking and bandwidth stealing</a></h2>
  5722. <pre class="prettyprint lang-config">
  5723. RewriteEngine On
  5724. RewriteBase /
  5725. RewriteCond %{HTTP_REFERER} !^$
  5726. RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache\.com/.*$ [NC]
  5727. RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]
  5728. </pre>
  5729.  
  5730.  
  5731. <h2><a href="#stop-browser-prefetching" name="stop-browser-prefetching" id="stop-browser-prefetching" title="Stop browser prefetching" class="acd">Stop browser prefetching</a></h2>
  5732. <pre class="prettyprint lang-config">
  5733. RewriteEngine On
  5734. SetEnvIfNoCase X-Forwarded-For .+ proxy=yes
  5735. SetEnvIfNoCase X-moz prefetch no_access=yes
  5736.  
  5737. # block pre-fetch requests with X-moz headers
  5738. RewriteCond %{ENV:no_access} yes
  5739. RewriteRule .* - [F,L]
  5740. </pre>
  5741.  
  5742.  
  5743.  
  5744. <blockquote cite="http://askapache.info/trunk/mod/mod_rewrite.html#rewritebase">
  5745. <p>This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule, to provide a really flexible and powerful URL manipulation mechanism. The URL manipulations can depend on various tests, of server variables, environment variables, HTTP headers, or time stamps. Even external database lookups in various formats can be used to achieve highly granular URL matching.</p>
  5746. <p>This module operates on the full URLs (including the path-info part) both in per-server context (<code>httpd.conf</code>) and per-directory context (<code>.htaccess</code>) and can generate query-string parts on result. The rewritten result can lead to internal sub-processing, external request redirection or even to an internal proxy throughput.</p>
  5747. <p>Further details, discussion, and examples, are provided in the <a href="http://askapache.info/trunk/rewrite/index.html">detailed mod_rewrite documentation</a>.</p>
  5748. </blockquote>
  5749. <h2>Directives</h2>
  5750. <ul>
  5751.    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritebase">RewriteBase</a></li>
  5752.    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritecond">RewriteCond</a></li>
  5753.    <li><a href="http://askapache.info/2.2/mod/mod_rewrite.html#rewriteengine">RewriteEngine</a></li>
  5754.    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritelock">RewriteLock</a></li>
  5755.    <li><a href="http://askapache.info/2.0/mod/mod_rewrite.html#rewritelog">RewriteLog</a></li>
  5756.    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewriteloglevel">RewriteLogLevel</a></li>
  5757.    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritemap">RewriteMap</a></li>
  5758.    <li><a href="http://askapache.info/1.3/mod/mod_rewrite.html#rewriteoptions">RewriteOptions</a></li>
  5759.    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewriterule">RewriteRule</a></li>
  5760. </ul>
  5761.  
  5762.  
  5763.  
  5764. <p>If you aren't already comfortable using mod_rewrite then I recommend this <a href="http://check-these.info/mod_rewrite-basic.html">excellent mod_rewrite guide</a> by one of my favorite mod_rewrite gurus that I've met.</p>
  5765.  
  5766.  
  5767.  
  5768. <p><a rel="nofollow" href="https://www.askapache.com/htaccess/modrewrite-tips-tricks/">Htaccess Rewrites &#8211; Rewrite Tricks and Tips</a> from <a rel="nofollow" href="https://www.askapache.com">AskApache</a></p>
  5769. ]]></content:encoded>
  5770. <wfw:commentRss>https://www.askapache.com/htaccess/modrewrite-tips-tricks/feed/</wfw:commentRss>
  5771. <slash:comments>154</slash:comments>
  5772. </item>
  5773. </channel>
  5774. </rss>
  5775.  
Copyright © 2002-9 Sam Ruby, Mark Pilgrim, Joseph Walton, and Phil Ringnalda