diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2003-11-17 17:03:17 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2003-11-17 17:03:17 +0000 |
commit | f4f786080bd710064f8cba8c6f613957974800fd (patch) | |
tree | 76db3be675dfcebd1df1eac8fe06f2718772d9e9 /usr.sbin/httpd/htdocs/manual | |
parent | 6eeab970345ef543887b0cda91aca10c0a2817c2 (diff) |
import Apache 1.3.29 and mod_ssl 2.8.16
Diffstat (limited to 'usr.sbin/httpd/htdocs/manual')
-rw-r--r-- | usr.sbin/httpd/htdocs/manual/FAQ.html | 3977 | ||||
-rw-r--r-- | usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.en | 2103 | ||||
-rw-r--r-- | usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.html | 2107 | ||||
-rw-r--r-- | usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.ja.jis | 2102 |
4 files changed, 10289 insertions, 0 deletions
diff --git a/usr.sbin/httpd/htdocs/manual/FAQ.html b/usr.sbin/httpd/htdocs/manual/FAQ.html new file mode 100644 index 00000000000..e25fe07b58d --- /dev/null +++ b/usr.sbin/httpd/htdocs/manual/FAQ.html @@ -0,0 +1,3977 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta name="generator" content="HTML Tidy, see www.w3.org" /> + + <title>Apache Server Frequently Asked Questions</title> + + </head> + <!-- Background white, links blue (unvisited), navy (visited), red (active) --> + + <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" + vlink="#000080" alink="#FF0000"> + <div align="CENTER"> + <img src="../images/sub.gif" alt="[APACHE DOCUMENTATION]" /> + + <h3>Apache HTTP Server Version 1.3</h3> + </div> + + + <h1 align="CENTER">Apache Server Frequently Asked + Questions</h1> + + <p>The latest version of this FAQ is always available from the + main Apache web site, at <<a + href="http://httpd.apache.org/docs/misc/FAQ.html" + rel="Help"><samp>http://httpd.apache.org/docs/misc/FAQ.html</samp></a>>.</p> + <!-- Notes about changes: --> + <!-- - If adding a relative link to another part of the --> + <!-- documentation, *do* include the ".html" portion. There's a --> + <!-- good chance that the user will be reading the documentation --> + <!-- on his own system, which may not be configured for --> + <!-- multiviews. --> + <!-- - When adding items, make sure they're put in the right place --> + <!-- - verify that the numbering matches up. --> + <!-- - *Don't* use <PRE></PRE> blocks - they don't appear --> + <!-- correctly in a reliable way when this is converted to text --> + <!-- with Lynx. Use <DL><DD><CODE>xxx<BR>xx</CODE></DD></DL> --> + <!-- blocks inside a <P></P> instead. This is necessary to get --> + <!-- the horizontal and vertical indenting right. --> + <!-- - Don't forget to include an HR tag after the last /P tag --> + <!-- but before the /LI in an item. --> + + <p>If you are reading a text-only version of this FAQ, you may + find numbers enclosed in brackets (such as "[12]"). These refer + to the list of reference URLs to be found at the end of the + document. These references do not appear, and are not needed, + for the hypertext version.</p> + + <h2>The Questions</h2> + <!-- Stuff to Add: --> + <!-- - can't bind to port 80 --> + <!-- - permission denied --> + <!-- - address already in use --> + <!-- - mod_auth & passwd lines "user:pw:.*" - ++1st colon onward is --> + <!-- treated as pw, not just ++1st to \-\-2nd. --> + <!-- - SSL: --> + <!-- - Can I use Apache-SSL for free in Canada? --> + <!-- - Why can't I use Apache-SSL in the U.S.? --> + <!-- - How can I found out how many visitors my site gets? --> + <!-- - How do I add a counter? --> + <!-- - How do I configure Apache as a proxy? --> + <!-- - What browsers support HTTP/1.1? --> + <!-- - What's the point of vhosts-by-name is there aren't any --> + <!-- HTTP/1.1 browsers? --> + <!-- - Is there an Apache for W95/WNT? --> + <!-- - Why does Apache die when a vhost can't be DNS-resolved? --> + <!-- - Why do I get "send lost connection" messages in my error --> + <!-- log? --> + <!-- - specifically consider .pdf files which seem to cause this --> + <!-- a lot when accessed via the plugin ... and also mention --> + <!-- how range-requests can cause bytes served < file size --> + <!-- - Why do directory indexes appear as garbage? (A: -lucb) --> + <!-- - How do I add a footer to all pages offered by my server? --> + <!-- - Fix midi question; a bigger problem than midi vs. x-midi is --> + <!-- the simple fact that older versions of Apache (and new ones --> + <!-- that have been upgraded without upgrading the mime.types --> + <!-- file) don't have the type listed at all. --> + <!-- - RewriteRule /~fraggle/* /cgi-bin/fraggle.pl does not work --> + <!-- - how do I disable authentication for a subdirectory? --> + <!-- (A: you can't but "Satisfy any; Allow from all" can be close --> + <!-- - '400 malformed request' on Win32 might mean stale proxy; see --> + <!-- PR #2300. --> + <!-- - how do I tell what version of Apache I am running? --> + + <ol type="A"> + + + + + + + + + + + + <li value="1"> + <strong>Background</strong> + + <ol> + <li><a href="#what">What is Apache?</a></li> + + <li><a href="#why">How and why was Apache + created?</a></li> + + <li><a href="#name">Why the name "Apache"?</a></li> + + <li><a href="#compare">OK, so how does Apache compare to + other servers?</a></li> + + <li><a href="#tested">How thoroughly tested is + Apache?</a></li> + + <li><a href="#future">What are the future plans for + Apache?</a></li> + + <li><a href="#support">Whom do I contact for + support?</a></li> + + <li><a href="#more">Is there any more information on + Apache?</a></li> + + <li><a href="#where">Where can I get Apache?</a></li> + + <li><a href="#logo">May I use the Apache logo on my + product or Web site?</a></li> + </ol> + </li> + + + + + </body> +</html> + + + + + + + + + + + + + + <li value="2"> + <strong>General Technical Questions</strong> + + <ol> + <li><a href="#what2do">"Why can't I ...? Why won't ... + work?" What to do in case of problems</a></li> + + <li><a href="#compatible">How compatible is Apache with + my existing NCSA 1.3 setup?</a></li> + + <li><a href="#year2000">Is Apache Year 2000 + compliant?</a></li> + + <li><a href="#submit_patch">How do I submit a patch to + the Apache Group?</a></li> + + <li><a href="#domination">Why has Apache stolen my + favourite site's Internet address?</a></li> + + <li><a href="#apspam">Why am I getting spam mail from the + Apache site?</a></li> + + <li><a href="#redist">May I include the Apache software + on a CD or other package I'm distributing?</a></li> + + <li><a href="#zoom">What's the best hardware/operating + system/... How do I get the most out of my Apache Web + server?</a></li> + + <li><a href="#regex">What are "regular + expressions"?</a></li> + + <li><a href="#binaries">Why isn't there a binary for my + platform?</a></li> + </ol> + </li> + + + + + </body> +</html> + + + + + + + + + + + + + + <li value="3"> + <strong>Building Apache</strong> + + <ol> + <li><a href="#bind8.1">Why do I get an error about an + undefined reference to "<samp>__inet_ntoa</samp>" or + other <samp>__inet_*</samp> symbols?</a></li> + + <li><a href="#cantbuild">Why won't Apache compile with my + system's <samp>cc</samp>?</a></li> + + <li><a href="#linuxiovec">Why do I get complaints about + redefinition of "<code>struct iovec</code>" when + compiling under Linux?</a></li> + + <li><a href="#broken-gcc">I'm using gcc and I get some + compilation errors, what is wrong?</a></li> + + <li><a href="#glibc-crypt">I'm using RedHat Linux 5.0, or + some other <samp>glibc</samp>-based Linux system, and I + get errors with the <code>crypt</code> function when I + attempt to build Apache 1.2.</a></li> + </ol> + </li> + + + + + </body> +</html> + + + + + + + + + + + + + + <li value="4"> + <strong>Error Log Messages and Problems Starting + Apache</strong> + + <ol> + <li><a href="#setgid">Why do I get "<samp>setgid: Invalid + argument</samp>" at startup?</a></li> + + <li><a href="#nodelay">Why am I getting "<samp>httpd: + could not set socket option TCP_NODELAY</samp>" in my + error log?</a></li> + + <li><a href="#peerreset">Why am I getting + "<samp>connection reset by peer</samp>" in my error + log?</a></li> + + <li><a href="#wheres-the-dump">The errorlog says Apache + dumped core, but where's the dump file?</a></li> + + <li><a href="#linux-shmget">When I run it under Linux I + get "shmget: function not found", what should I + do?</a></li> + + <li><a href="#nfslocking">Server hangs, or fails to + start, and/or error log fills with "<samp>fcntl: + F_SETLKW: No record locks available</samp>" or similar + messages</a></li> + + <li><a href="#aixccbug">Why am I getting "<samp>Expected + </Directory> but saw </Directory></samp>" + when I try to start Apache?</a></li> + + <li><a href="#redhat">I'm using RedHat Linux and I have + problems with httpd dying randomly or not restarting + properly</a></li> + + <li><a href="#stopping">I upgraded from an Apache version + earlier than 1.2.0 and suddenly I have problems with + Apache dying randomly or not restarting properly</a></li> + + <li><a href="#setservername">When I try to start Apache + from a DOS window, I get a message like "<samp>Cannot + determine host name. Use ServerName directive to set it + manually.</samp>" What does this mean?</a></li> + + <li><a href="#ws2_32dll">When I try to start Apache for + Windows, I get a message like "<samp>Unable To Locate + WS2_32.DLL...</samp>". What should I do?</a></li> + + <li><a href="#WSADuplicateSocket">Apache for Windows does + not start. Error log contains this message "<samp>[crit] + (10045) The attempted operation is not supported for the + type of object referenced: Parent: WSADuplicateSocket + failed for socket ###</samp>". What does this + mean?</a></li> + + <li><a href="#err1067">When I try to start Apache on + Windows, I get a message like "<code>System error 1067 + has occurred. The process terminated + unexpectedly.</code>" What does this mean?</a></li> + + <li><a href="#suseFDN">On a SuSE Linux system, I try and + configure access control using basic authentication. + Although I follow the example exactly, authentication + fails, and an error message "<code>admin: not a valid + FDN: ....</code>" is logged.</a></li> + + <li><a href="#codered">Why do I have weird entries in my + logs asking for <code>default.ida</code> and + <code>cmd.exe</code>?</a></li> + + <li><a href="#restart">Why am I getting server restart + messages periodically, when I did not restart the + server?</a></li> + + <li><a href="#modulemagic">Why am I getting "module + <em>module-name</em> is not compatible with this version of + Apache" messages in my error log?</a></li> + + </ol> + </li> + + + + + </body> +</html> + + + + + + + + + + + + + + <li value="5"> + <strong>Configuration Questions</strong> + + <ol> + <li><a href="#fdlim">Why can't I run more than + <<em>n</em>> virtual hosts?</a></li> + + <li><a href="#freebsd-setsize">Can I increase + <samp>FD_SETSIZE</samp> on FreeBSD?</a></li> + + <li><a href="#errordoc401">Why doesn't my + <code>ErrorDocument 401</code> work?</a></li> + + <li><a href="#cookies1">Why does Apache send a cookie on + every response?</a></li> + + <li><a href="#cookies2">Why don't my cookies work, I even + compiled in <samp>mod_cookies</samp>?</a></li> + + <li><a href="#jdk1-and-http1.1">Why do my Java app[let]s + give me plain text when I request an URL from an Apache + server?</a></li> + + <li><a href="#midi">How do I get Apache to send a MIDI + file so the browser can play it?</a></li> + + <li><a href="#addlog">How do I add browsers and referrers + to my logs?</a></li> + + <li><a href="#set-servername">Why does accessing + directories only work when I include the trailing "/" + (<em>e.g.</em>, <samp>http://foo.domain.com/~user/</samp>) + but not when I omit it + (<em>e.g.</em>, <samp>http://foo.domain.com/~user</samp>)?</a></li> + + <li><a href="#no-info-directives">Why doesn't mod_info + list any directives?</a></li> + + <li><a href="#namevhost">I upgraded to Apache 1.3 and now + my virtual hosts don't work!</a></li> + + <li><a href="#redhat-htm">I'm using RedHat Linux and my + .htm files are showing up as HTML source rather than + being formatted!</a></li> + + <li><a href="#htaccess-work">My <code>.htaccess</code> + files are being ignored.</a></li> + + <li><a href="#forbidden">Why do I get a + "<samp>Forbidden</samp>" message whenever I try to access + a particular directory?</a></li> + + <li><a href="#malfiles">Why do I get a + "<samp>Forbidden/You don't have permission to access / on + this server</samp>" message whenever I try to access my + server?</a></li> + + <li><a href="#ie-ignores-mime">Why do my files appear + correctly in Internet Explorer, but show up as source or + trigger a save window with Netscape; or, Why doesn't + Internet Explorer render my text/plain document + correctly?</a></li> + + <li><a href="#canonical-hostnames">My site is accessible + under many different hostnames; how do I redirect clients + so that they see only a single name?</a></li> + + <li><a href="#firewall">Why can I access my website from the + server or from my local network, but I can't access it from + elsewhere on the Internet?</a></li> + + <li><a href="#indexes">How do I turn automatic directory listings + on or off?</a></li> + + <li><a href="#options">Why do my Options directives not have + the desired effect?</a></li> + + <li><a href="#serverheader">How can I change the information + that Apache returns about itself in the headers?</a></li> + + <li><a href="#proxyscan">Why do I see requests for other sites + appearing in my log files?</a></li> + + </ol> + </li> + + + + + </body> +</html> + + + + + + + + + + + + + + <li value="6"> + <strong>Dynamic Content (CGI and SSI)</strong> + + <ol> + <li><a href="#CGIoutsideScriptAlias">How do I enable CGI + execution in directories other than the + ScriptAlias?</a></li> + + <li><a href="#premature-script-headers">What does it mean + when my CGIs fail with "<samp>Premature end of script + headers</samp>"?</a></li> + + <li><a href="#POSTnotallowed">Why do I keep getting + "Method Not Allowed" for form POST requests?</a></li> + + <li><a href="#nph-scripts">How can I get my script's + output without Apache buffering it? Why doesn't my server + push work?</a></li> + + <li><a href="#cgi-spec">Where can I find the "CGI + specification"?</a></li> + + <li><a href="#fastcgi">Why isn't FastCGI included with + Apache any more?</a></li> + + <li><a href="#ssi-part-i">How do I enable SSI (parsed + HTML)?</a></li> + + <li><a href="#ssi-part-ii">Why don't my parsed files get + cached?</a></li> + + <li><a href="#ssi-part-iii">How can I have my script + output parsed?</a></li> + + <li><a href="#ssi-part-iv">SSIs don't work for + VirtualHosts and/or user home directories</a></li> + + <li><a href="#errordocssi">How can I use + <code>ErrorDocument</code> and SSI to simplify customized + error messages?</a></li> + + <li><a href="#remote-user-var">Why is the environment + variable <samp>REMOTE_USER</samp> not set?</a></li> + + <li><a href="#user-cgi">How do I allow each of my user + directories to have a cgi-bin directory?</a></li> + </ol> + </li> + + + + + </body> +</html> + + + + + + + + + + + + + + <li value="7"> + <strong>Authentication and Access Restrictions</strong> + + <ol> + <li><a href="#dnsauth">Why isn't restricting access by + host or domain name working correctly?</a></li> + + <li><a href="#user-authentication">How do I set up Apache + to require a username and password to access certain + documents?</a></li> + + <li><a href="#remote-auth-only">How do I set up Apache to + allow access to certain documents only if a site is + either a local site <em>or</em> the user supplies a + password and username?</a></li> + + <li><a href="#authauthoritative">Why does my + authentication give me a server error?</a></li> + + <li><a href="#auth-on-same-machine">Do I have to keep the + (mSQL) authentication information on the same + machine?</a></li> + + <li><a href="#msql-slow">Why is my mSQL authentication + terribly slow?</a></li> + + <li><a href="#passwdauth">Can I use my + <samp>/etc/passwd</samp> file for Web page + authentication?</a></li> + + <li><a href="#prompted-twice">Why does Apache ask for my + password twice before serving a file?</a></li> + + <li><a href="#image-theft">How can I prevent people from + "stealing" the images from my web site?</a></li> + + </ol> + </li> + + + + + </body> +</html> + + + + + + + + + + + + + + <li value="8"> + <strong>URL Rewriting</strong> + + <ol> + <li><a href="#rewrite-more-config">Where can I find + mod_rewrite rulesets which already solve particular + URL-related problems?</a></li> + + <li><a href="#rewrite-article">Where can I find any + published information about URL-manipulations and + mod_rewrite?</a></li> + + <li><a href="#rewrite-complexity">Why is mod_rewrite so + difficult to learn and seems so complicated?</a></li> + + <li><a href="#rewrite-dontwork">What can I do if my + RewriteRules don't work as expected?</a></li> + + <li><a href="#rewrite-prefixdocroot">Why don't some of my + URLs get prefixed with DocumentRoot when using + mod_rewrite?</a></li> + + <li><a href="#rewrite-nocase">How can I make all my URLs + case-insensitive with mod_rewrite?</a></li> + + <li><a href="#rewrite-virthost">Why are RewriteRules in + my VirtualHost parts ignored?</a></li> + + <li><a href="#rewrite-envwhitespace">How can I use + strings with whitespaces in RewriteRule's ENV + flag?</a></li> + </ol> + </li> + + + + + </body> +</html> + + + + + + + + + + + + + + <li value="9"> + <strong>Features</strong> + + <ol> + <li><a href="#proxy">Does or will Apache act as a Proxy + server?</a></li> + + <li><a href="#multiviews">What are "multiviews"?</a></li> + + <li><a href="#putsupport">Why can't I publish to my + Apache server using PUT on Netscape Gold and other + programs?</a></li> + + <li><a href="#SSL-i">Why doesn't Apache include + SSL?</a></li> + + <li><a href="#footer">How can I attach a footer to my + documents without using SSI?</a></li> + + <li><a href="#search">Does Apache include a search + engine?</a></li> + + <li><a href="#rotate">How can I rotate my log + files?</a></li> + + <li><a href="#conditional-logging">How do I keep certain + requests from appearing in my logs?</a></li> + + <li><a href="#dbinteg">Does Apache include any sort of + database integration?</a></li> + + <li><a href="#asp">Can I use Active Server Pages (ASP) + with Apache?</a></li> + + <li><a href="#java">Does Apache come with Java + support?</a></li> + </ol> + </li> + + + + + </body> +</html> + + + </ol> + <hr /> + + <h2>The Answers</h2> + + + + + + + + + + + + + + <h3>A. Background</h3> + + <ol> + <li> + <a id="what" name="what"><strong>What is + Apache?</strong></a> + + <p>The Apache httpd server</p> + + <ul> + <li>is a powerful, flexible, HTTP/1.1 compliant web + server</li> + + <li>implements the latest protocols, including HTTP/1.1 + (RFC2616)</li> + + <li>is highly configurable and extensible with + third-party modules</li> + + <li>can be customised by writing 'modules' using the + Apache module API</li> + + <li>provides full source code and comes with an + unrestrictive license</li> + + <li>runs on Windows NT/9x, Netware 5.x and above, OS/2, and most + versions of Unix, as well as several other operating + systems</li> + + <li>is actively being developed</li> + + <li>encourages user feedback through new ideas, bug + reports and patches</li> + + <li> + implements many frequently requested features, + including:<br /> + <br /> + + + <dl> + <dt>DBM databases for authentication</dt> + + <dd>allows you to easily set up password-protected + pages with enormous numbers of authorized users, + without bogging down the server.</dd> + + <dt>Customized responses to errors and problems</dt> + + <dd>Allows you to set up files, or even CGI scripts, + which are returned by the server in response to + errors and problems, e.g. setup a script to intercept + <strong>500 Server Error</strong>s and perform + on-the-fly diagnostics for both users and + yourself.</dd> + + <dt>Multiple DirectoryIndex directives</dt> + + <dd>Allows you to say <code>DirectoryIndex index.html + index.cgi</code>, which instructs the server to + either send back <code>index.html</code> or run + <code>index.cgi</code> when a directory URL is + requested, whichever it finds in the directory.</dd> + + <dt>Unlimited flexible URL rewriting and + aliasing</dt> + + <dd>Apache has no fixed limit on the numbers of + Aliases and Redirects which may be declared in the + config files. In addition, a powerful rewriting + engine can be used to solve most URL manipulation + problems.</dd> + + <dt>Content negotiation</dt> + + <dd>i.e. the ability to automatically serve clients + of varying sophistication and HTML level compliance, + with documents which offer the best representation of + information that the client is capable of + accepting.</dd> + + <dt>Virtual Hosts</dt> + + <dd>A much requested feature, sometimes known as + multi-homed servers. This allows the server to + distinguish between requests made to different IP + addresses or names (mapped to the same machine). + Apache also offers dynamically configurable + mass-virtual hosting.</dd> + + <dt>Configurable Reliable Piped Logs</dt> + + <dd>You can configure Apache to generate logs in the + format that you want. In addition, on most Unix + architectures, Apache can send log files to a pipe, + allowing for log rotation, hit filtering, real-time + splitting of multiple vhosts into separate logs, and + asynchronous DNS resolving on the fly.</dd> + </dl> + </li> + </ul> + <hr /> + </li> + + <li> + <a id="why" name="why"><strong>How and why was Apache + created?</strong></a> + + <p>The <a + href="http://httpd.apache.org/ABOUT_APACHE.html">About + Apache</a> document explains how the Apache project evolved + from its beginnings as an outgrowth of the NCSA httpd + project to its current status as one of the fastest, most + efficient, and most functional web servers in + existence.</p> + <hr /> + </li> + + <li> + <a id="name" name="name"><strong>Why the name + "Apache"?</strong></a> + + <p>The name 'Apache' was chosen from respect for + the Native American Indian tribe of Apache (Indé), + <a href="http://www.indians.org/welker/apache.htm">well-known + for their superior skills in warfare strategy and their + inexhaustible endurance</a>. For more information on the + Apache Nation, we suggest searching + <a href="http://www.google.com/search?q=Apache+Nation">Google</a>, + <a href="http://www.northernlight.com/nlquery.fcg?qr=Apache+Nation" + >Northernlight</a>, or + <a href="http://www.alltheweb.com/cgi-bin/asearch?query=Apache+Nation" + >AllTheWeb</a>.</p> + + <p>Secondarily, and more popularly (though incorrectly) accepted, + it's a considered cute name which stuck. Apache is "<strong>A + PA</strong>t<strong>CH</strong>y server". It was based on + some existing code and a series of "patch files".</p> + + <hr /> + </li> + + <li> + <a id="compare" name="compare"><strong>OK, so how does + Apache compare to other servers?</strong></a> + + <p>For an independent assessment, see <a + href="http://webcompare.internet.com/">Web + Compare</a>.</p> + + <p>Apache has been shown to be substantially faster, more + stable, and more feature-full than many other web servers. + Although certain commercial servers have claimed to surpass + Apache's speed (it has not been demonstrated that any of + these "benchmarks" are a good way of measuring WWW server + speed at any rate), we feel that it is better to have a + mostly-fast free server than an extremely-fast server that + costs thousands of dollars. Apache is run on sites that get + millions of hits per day, and they have experienced no + performance difficulties.</p> + <hr /> + </li> + + <li> + <a id="tested" name="tested"><strong>How thoroughly tested + is Apache?</strong></a> + + <p>Apache is run on over 6 million Internet servers (as of + February 2000). It has been tested thoroughly by both + developers and users. The Apache Group maintains rigorous + standards before releasing new versions of their server, + and our server runs without a hitch on over one half of all + WWW servers available on the Internet. When bugs do show + up, we release patches and new versions as soon as they are + available.</p> + <hr /> + </li> + + <li> + <a id="future" name="future"><strong>What are the future + plans for Apache?</strong></a> + + <ul> + <li>to continue to be an "open source" no-charge-for-use + HTTP server,</li> + + <li>to keep up with advances in HTTP protocol and web + developments in general,</li> + + <li>to collect suggestions for fixes/improvements from + its users,</li> + + <li>to respond to needs of large volume providers as well + as occasional users.</li> + </ul> + <hr /> + </li> + + <li> + <a id="support" name="support"><strong>Whom do I contact + for support?</strong></a> + + <p>There is no official support for Apache. None of the + developers want to be swamped by a flood of trivial + questions that can be resolved elsewhere. Bug reports and + suggestions should be sent <em>via</em> <a + href="http://httpd.apache.org/bug_report.html">the bug + report page</a>. Other questions should be directed to the + <a href="http://httpd.apache.org/userslist.html">Apache HTTP + Server Users List</a> or the + <a + href="news:comp.infosystems.www.servers.unix">comp.infosystems.www.servers.unix</a> + or <a + href="news:comp.infosystems.www.servers.ms-windows">comp.infosystems.www.servers.ms-windows</a> + newsgroup (as appropriate for the platform you use), where + some of the Apache team lurk, in the company of many other + httpd gurus who should be able to help.</p> + + <p>Commercial support for Apache is, however, available + from a number of third parties.</p> + <hr /> + </li> + + <li> + <a id="more" name="more"><strong>Is there any more + information available on Apache?</strong></a> + + <p>Indeed there is. See the main <a + href="http://httpd.apache.org/">Apache web site</a>. There + is also a regular electronic publication called <a + href="http://www.apacheweek.com/" rel="Help"><cite>Apache + Week</cite></a> available. Links to relevant <cite>Apache + Week</cite> articles are included below where appropriate. + There are also some <a + href="http://httpd.apache.org/info/apache_books.html">Apache-specific + books</a> available.</p> + <hr /> + </li> + + <li> + <a id="where" name="where"><strong>Where can I get + Apache?</strong></a> + + <p>You can find out how to download the source for Apache + at the project's <a href="http://httpd.apache.org/">main + web page</a>.</p> + <hr /> + </li> + + <li> + <a id="logo" name="logo"><b>May I use the Apache logo on my + product or Web site?</b></a> + + <p>You may <b>NOT</b> use any original artwork from the + Apache Software Foundation, nor make or use modified + versions of such artwork, except under the following + conditions:</p> + + <ul> + <li>You may use the <a + href="../../apache_pb.gif">'Powered by Apache' + graphic</a> on a Web site that is being served by the + Apache HTTP server software.</li> + + <li>You may use the aforementioned 'Powered by Apache' + graphic or the <a + href="http://www.apache.org/images/asf_logo.gif"> + Apache Software Foundation logo</a> in product + description and promotional material <b>IF and ONLY + IF</b> such use can in no way be interpreted as anything + other than an attribution. Using the Apache name and + artwork in a manner that implies endorsement of a product + or service is <b>strictly forbidden</b>.</li> + </ul> + <hr /> + </li> + </ol> + + + </body> +</html> + + + + + + + + + + + + + + + + <h3>B. General Technical Questions</h3> + + <ol> + <li> + <a id="what2do" name="what2do"><strong>"Why can't I ...? + Why won't ... work?" What to do in case of + problems</strong></a> + + <p>If you are having trouble with your Apache server + software, you should take the following steps:</p> + + <ol> + <li> + <strong>Check the errorlog!</strong> + + <p>Apache tries to be helpful when it encounters a + problem. In many cases, it will provide some details by + writing one or messages to the server error log. + Sometimes this is enough for you to diagnose & fix + the problem yourself (such as file permissions or the + like). The default location of the error log is + <samp>/usr/local/apache/logs/error_log</samp>, but see + the <a + href="../mod/core.html#errorlog"><samp>ErrorLog</samp></a> + directive in your config files for the location on your + server.</p> + </li> + + <li> + <strong>Check the <a + href="http://httpd.apache.org/docs/misc/FAQ.html">FAQ</a>!</strong> + + + <p>The latest version of the Apache Frequently-Asked + Questions list can always be found at the main Apache + web site.</p> + </li> + + <li> + <strong>Check the Apache bug database</strong> + + <p>Most problems that get reported to The Apache Group + are recorded in the <a + href="http://bugs.apache.org/">bug database</a>. + <em><strong>Please</strong> check the existing reports, + open <strong>and</strong> closed, before adding + one.</em> If you find that your issue has already been + reported, please <em>don't</em> add a "me, too" report. + If the original report isn't closed yet, we suggest + that you check it periodically. You might also consider + contacting the original submitter, because there may be + an email exchange going on about the issue that isn't + getting recorded in the database.</p> + </li> + + <li> + <strong>Ask in a user support group.</strong> + + <p>A lot of common problems never make it to the bug + database because there's already high Q&A traffic + about them in the <a + href="http://httpd.apache.org/userslist.html">Users + mailing list</a> or <a + href="news:comp.infosystems.www.servers.unix"><samp>comp.infosystems.www.servers.unix</samp></a> + and related newsgroups. These newsgroups are also + available via <a + href="http://groups.google.com/groups?group=comp.infosystems.www.servers"> + Google</a>. Many Apache users, and some of the developers, + can be found roaming their virtual halls, so it is suggested + that you seek wisdom there. The chances are good that + you'll get a faster answer there than from the bug + database, even if you <em>don't</em> see your question + already posted.</p> + </li> + + <li> + <strong>If all else fails, report the problem in the + bug database</strong> + + <p>If you've gone through those steps above that are + appropriate and have obtained no relief, then please + <em>do</em> let The Apache Group know about the problem + by <a + href="http://httpd.apache.org/bug_report.html">logging + a bug report</a>.</p> + + <p>If your problem involves the server crashing and + generating a core dump, please include a backtrace (if + possible). As an example,</p> + + <dl> + <dd><code># cd <em>ServerRoot</em><br /> + # dbx httpd core<br /> + (dbx) where</code></dd> + </dl> + + <p>(Substitute the appropriate locations for your + <samp>ServerRoot</samp> and your <samp>httpd</samp> and + <samp>core</samp> files. You may have to use + <code>gdb</code> instead of <code>dbx</code>.)</p> + </li> + </ol> + <hr /> + </li> + + <li> + <a id="compatible" name="compatible"><strong>How compatible + is Apache with my existing NCSA 1.3 setup?</strong></a> + + <p>Apache attempts to offer all the features and + configuration options of NCSA httpd 1.3, as well as many of + the additional features found in NCSA httpd 1.4 and NCSA + httpd 1.5.</p> + + <p>NCSA httpd appears to be moving toward adding + experimental features which are not generally required at + the moment. Some of the experiments will succeed while + others will inevitably be dropped. The Apache philosophy is + to add what's needed as and when it is needed.</p> + + <p>Friendly interaction between Apache and NCSA developers + should ensure that fundamental feature enhancements stay + consistent between the two servers for the foreseeable + future.</p> + <hr /> + </li> + + <li> + <a id="year2000" name="year2000"><strong>Is Apache Year + 2000 compliant?</strong></a> + + <p>Yes, Apache is Year 2000 compliant.</p> + + <p>Apache internally never stores years as two digits. On + the HTTP protocol level RFC1123-style addresses are + generated which is the only format a HTTP/1.1-compliant + server should generate. To be compatible with older + applications Apache recognizes ANSI C's + <code>asctime()</code> and RFC850-/RFC1036-style date + formats, too. The <code>asctime()</code> format uses + four-digit years, but the RFC850 and RFC1036 date formats + only define a two-digit year. If Apache sees such a date + with a value less than 70 it assumes that the century is + <samp>20</samp> rather than <samp>19</samp>.</p> + + <p>Although Apache is Year 2000 compliant, you may still + get problems if the underlying OS has problems with dates + past year 2000 (<em>e.g.</em>, OS calls which accept or + return year numbers). Most (UNIX) systems store dates + internally as signed 32-bit integers which contain the + number of seconds since 1<sup>st</sup> January 1970, so the + magic boundary to worry about is the year 2038 and not + 2000. But modern operating systems shouldn't cause any + trouble at all.</p> + + <p>Users of Apache 1.2.x should upgrade to a current + version of Apache 1.3 (see <a + href="../new_features_1_3.html#misc">year-2000 improvements + in Apache 1.3</a> for details).</p> + + <p>The Apache HTTP Server project is an open-source + software product of the Apache Software Foundation. The + project and the Foundation <b>cannot</b> offer legal + assurances regarding any suitability of the software for + your application. There are several commercial Apache + support organizations and derivative server products + available that may be able to stand behind the software and + provide you with any assurances you may require. You may + find links to some of these vendors at <samp><<a + href="http://www.apache.org/info/support.cgi">http://www.apache.org/info/support.cgi</a>></samp>.</p> + + <p>The Apache HTTP server software is distributed with the + following disclaimer, found in the software license:</p> +<pre> + THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY + EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR + ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + OF THE POSSIBILITY OF SUCH DAMAGE. + +</pre> + <hr /> + </li> + + <li> + <a id="submit_patch" name="submit_patch"><strong>How do I + submit a patch to the Apache Group?</strong></a> + + <p>The Apache Group encourages patches from outside + developers. There are 2 main "types" of patches: small + bugfixes and general improvements. Bugfixes should be + submitting using the Apache <a + href="http://httpd.apache.org/bug_report.html">bug report + page</a>. Improvements, modifications, and additions should + follow the instructions below.</p> + + <p>In general, the first course of action is to be a member + of the <samp>dev@httpd.apache.org</samp> mailing list. This + indicates to the Group that you are closely following the + latest Apache developments. Your patch file should be + generated using either '<code>diff -c</code>' or + '<code>diff -u</code>' against the latest CVS tree. To + submit your patch, send email to + <samp>dev@httpd.apache.org</samp> with a + <samp>Subject:</samp> line that starts with + <samp>[PATCH]</samp> and includes a general description of + the patch. In the body of the message, the patch should be + clearly described and then included at the end of the + message. If the patch-file is long, you can note a URL to + the file instead of the file itself. Use of MIME + enclosures/attachments should be avoided.</p> + + <p>Be prepared to respond to any questions about your + patches and possibly defend your code. If your patch + results in a lot of discussion, you may be asked to submit + an updated patch that incorporates all changes and + suggestions.</p> + <hr /> + </li> + + <li> + <a id="domination" name="domination"><strong>Why has Apache + stolen my favourite site's Internet address?</strong></a> + + <p>The simple answer is: "It hasn't." This misconception is + usually caused by the site in question having migrated to + the Apache Web server software, but not having migrated the + site's content yet. When Apache is installed, the default + page that gets installed tells the Webmaster the + installation was successful. The expectation is that this + default page will be replaced with the site's real content. + If it doesn't, complain to the Webmaster, not to the Apache + project -- we just make the software and aren't responsible + for what people do (or don't do) with it.</p> + <hr /> + </li> + + <li> + <a id="apspam" name="apspam"><strong>Why am I getting spam + mail from the Apache site?</strong></a> + + <p>The short answer is: "You aren't." Usually when someone + thinks the Apache site is originating spam, it's because + they've traced the spam to a Web site, and the Web site + says it's using Apache. See the <a + href="#domination">previous FAQ entry</a> for more details + on this phenomenon.</p> + + <p>No marketing spam originates from the Apache site. The + only mail that comes from the site goes only to addresses + that have been <em>requested</em> to receive the mail.</p> + <hr /> + </li> + + <li> + <a id="redist" name="redist"><strong>May I include the + Apache software on a CD or other package I'm + distributing?</strong></a> + + <p>The detailed answer to this question can be found in the + Apache license, which is included in the Apache + distribution in the file <code>LICENSE</code>. You can also + find it on the Web at <samp><<a + href="http://www.apache.org/LICENSE.txt">http://www.apache.org/LICENSE.txt</a>></samp>.</p> + <hr /> + </li> + + <li> + <a id="zoom" name="zoom"><strong>What's the best + hardware/operating system/... How do I get the most out of + my Apache Web server?</strong></a> + + <p>Check out Dean Gaudet's <a + href="perf-tuning.html">performance tuning page</a>.</p> + <hr /> + </li> + + <li> + <a id="regex" name="regex"><strong>What are "regular + expressions"?</strong></a> + + <p>Regular expressions are a way of describing a pattern - + for example, "all the words that begin with the letter A" + or "every 10-digit phone number" or even "Every sentence + with two commas in it, and no capital letter Q". Regular + expressions (aka "regex"s) are useful in Apache because + they let you apply certain attributes against collections + of files or resources in very flexible ways - for example, + all .gif and .jpg files under any "images" directory could + be written as /\/images\/.*(jpg|gif)$/.</p> + + <p>The best overview around is probably the one which comes + with Perl. We implement a simple subset of Perl's regex + support, but it's still a good way to learn what they mean. + You can start by going to the <a + href="http://www.perl.com/doc/manual/html/pod/perlre.html">CPAN + page on regular expressions</a>, and branching out from + there.</p> <hr /> + </li> + + <li> + <a id="binaries" name="binaries"><b>Why isn't there a + binary for my platform?</b></a> + + <p>The developers make sure that the software builds and + works correctly on the platforms available to them; this + does <i>not</i> necessarily mean that <i>your</i> platform + is one of them. In addition, the Apache HTTP server project + is primarily source oriented, meaning that distributing + valid and buildable source code is the purpose of a + release, not making sure that there is a binary package for + all of the supported platforms.</p> + + <p>If you don't see a kit for your platform listed in the + binary distribution area (<URL:<a + href="http://httpd.apache.org/dist/httpd/binaries/">http://httpd.apache.org/dist/httpd/binaries/</a>>), + it means either that the platform isn't available to any of + the developers, or that they just haven't gotten around to + preparing a binary for it. As this is a voluntary project, + they are under no obligation to do so. Users are encouraged + and expected to build the software themselves.</p> + + <p>The sole exception to these practices is the Windows + package. Unlike most Unix and Unix-like platforms, Windows + systems do not come with a bundled software development + environment, so we <i>do</i> prepare binary kits for + Windows when we make a release. Again, however, it's a + voluntary thing and only a limited number of the developers + have the capability to build the InstallShield package, so + the Windows release may lag somewhat behind the source + release. This lag should be no more than a few days at + most.</p> + <hr /> + </li> + </ol> + + + </body> +</html> + + + + + + + + + + + + + + + + <h3>C. Building Apache</h3> + + <ol> + <li> + <a id="bind8.1" name="bind8.1"><strong>Why do I get an + error about an undefined reference to + "<samp>__inet_ntoa</samp>" or other <samp>__inet_*</samp> + symbols?</strong></a> + + <p>If you have installed <a + href="http://www.isc.org/bind.html">BIND-8</a> then this is + normally due to a conflict between your include files and + your libraries. BIND-8 installs its include files and + libraries <code>/usr/local/include/</code> and + <code>/usr/local/lib/</code>, while the resolver that comes + with your system is probably installed in + <code>/usr/include/</code> and <code>/usr/lib/</code>. If + your system uses the header files in + <code>/usr/local/include/</code> before those in + <code>/usr/include/</code> but you do not use the new + resolver library, then the two versions will conflict.</p> + + <p>To resolve this, you can either make sure you use the + include files and libraries that came with your system or + make sure to use the new include files and libraries. + Adding <code>-lbind</code> to the + <code>EXTRA_LDFLAGS</code> line in your + <samp>Configuration</samp> file, then re-running + <samp>Configure</samp>, should resolve the problem. (Apache + versions 1.2.* and earlier use <code>EXTRA_LFLAGS</code> + instead.)</p> + + <p><strong>Note:</strong>As of BIND 8.1.1, the bind + libraries and files are installed under + <samp>/usr/local/bind</samp> by default, so you should not + run into this problem. Should you want to use the bind + resolvers you'll have to add the following to the + respective lines:</p> + + <dl> + <dd><code>EXTRA_CFLAGS=-I/usr/local/bind/include<br /> + EXTRA_LDFLAGS=-L/usr/local/bind/lib<br /> + EXTRA_LIBS=-lbind</code></dd> + </dl> + <hr /> + </li> + + <li> + <a id="cantbuild" name="cantbuild"><strong>Why won't Apache + compile with my system's <samp>cc</samp>?</strong></a> + + <p>If the server won't compile on your system, it is + probably due to one of the following causes:</p> + + <ul> + <li><strong>The <samp>Configure</samp> script doesn't + recognize your system environment.</strong><br /> + This might be either because it's completely unknown or + because the specific environment (include files, OS + version, <em>et cetera</em>) isn't explicitly handled. If + this happens, you may need to port the server to your OS + yourself.</li> + + <li><strong>Your system's C compiler is + garbage.</strong><br /> + Some operating systems include a default C compiler that + is either not ANSI C-compliant or suffers from other + deficiencies. The usual recommendation in cases like this + is to acquire, install, and use <samp>gcc</samp>.</li> + + <li><strong>Your <samp>include</samp> files may be + confused.</strong><br /> + In some cases, we have found that a compiler + installation or system upgrade has left the C header + files in an inconsistent state. Make sure that your + include directory tree is in sync with the compiler and + the operating system.</li> + + <li><strong>Your operating system or compiler may be out + of revision.</strong><br /> + Software vendors (including those that develop operating + systems) issue new releases for a reason; sometimes to + add functionality, but more often to fix bugs that have + been discovered. Try upgrading your compiler and/or your + operating system.</li> + </ul> + + <p>The Apache Group tests the ability to build the server + on many different platforms. Unfortunately, we can't test + all of the OS platforms there are. If you have verified + that none of the above issues is the cause of your problem, + and it hasn't been reported before, please submit a <a + href="http://httpd.apache.org/bug_report.html">problem + report</a>. Be sure to include <em>complete</em> details, + such as the compiler & OS versions and exact error + messages.</p> + <hr /> + </li> + + <li> + <a id="linuxiovec" name="linuxiovec"><strong>Why do I get + complaints about redefinition of "<code>struct + iovec</code>" when compiling under Linux?</strong></a> + + <p>This is a conflict between your C library includes and + your kernel includes. You need to make sure that the + versions of both are matched properly. There are two + workarounds, either one will solve the problem:</p> + + <ul> + <li>Remove the definition of <code>struct iovec</code> + from your C library includes. It is located in + <code>/usr/include/sys/uio.h</code>. + <strong>Or,</strong></li> + + <li>Add <code>-DNO_WRITEV</code> to the + <code>EXTRA_CFLAGS</code> line in your + <samp>Configuration</samp> and reconfigure/rebuild. This + hurts performance and should only be used as a last + resort.</li> + </ul> + <hr /> + </li> + + <li> + <a id="broken-gcc" name="broken-gcc"><strong>I'm using gcc + and I get some compilation errors, what is + wrong?</strong></a> + + <p>GCC parses your system header files and produces a + modified subset which it uses for compiling. This behavior + ties GCC tightly to the version of your operating system. + So, for example, if you were running IRIX 5.3 when you + built GCC and then upgrade to IRIX 6.2 later, you will have + to rebuild GCC. Similarly for Solaris 2.4, 2.5, or 2.5.1 + when you upgrade to 2.6. Sometimes you can type "gcc -v" + and it will tell you the version of the operating system it + was built against.</p> + + <p>If you fail to do this, then it is very likely that + Apache will fail to build. One of the most common errors is + with <code>readv</code>, <code>writev</code>, or + <code>uio.h</code>. This is <strong>not</strong> a bug with + Apache. You will need to re-install GCC.</p> + <hr /> + </li> + + <li> + <a id="glibc-crypt" name="glibc-crypt"><strong>I'm using + RedHat Linux 5.0, or some other <samp>glibc</samp>-based + Linux system, and I get errors with the <code>crypt</code> + function when I attempt to build Apache 1.2.</strong></a> + + <p><samp>glibc</samp> puts the <code>crypt</code> function + into a separate library. Edit your + <code>src/Configuration</code> file and set this:</p> + + <dl> + <dd><code>EXTRA_LIBS=-lcrypt</code></dd> + </dl> + + <p>Then re-run <samp>src/Configure</samp> and re-execute + the make.</p> + <hr /> + </li> + </ol> + + + </body> +</html> + + + + + + + + + + + + + + + + <h3>D. Error Log Messages and Problems Starting Apache</h3> + + <ol> + <li> + <a id="setgid" name="setgid"><strong>Why do I get + "<samp>setgid: Invalid argument</samp>" at + startup?</strong></a> + + <p>Your <a + href="../mod/core.html#group"><samp>Group</samp></a> + directive (probably in <samp>conf/httpd.conf</samp>) needs + to name a group that actually exists in the + <samp>/etc/group</samp> file (or your system's equivalent). + This problem is also frequently seen when a negative number + is used in the <code>Group</code> directive (<em>e.g.</em>, + "<code>Group #-1</code>"). Using a group name -- not + group number -- found in your system's group database + should solve this problem in all cases.</p> + <hr /> + </li> + + <li> + <a id="nodelay" name="nodelay"><strong>Why am I getting + "<samp>httpd: could not set socket option + TCP_NODELAY</samp>" in my error log?</strong></a> + + <p>This message almost always indicates that the client + disconnected before Apache reached the point of calling + <code>setsockopt()</code> for the connection. It shouldn't + occur for more than about 1% of the requests your server + handles, and it's advisory only in any case.</p> + <hr /> + </li> + + <li> + <a id="peerreset" name="peerreset"><strong>Why am I getting + "<samp>connection reset by peer</samp>" in my error + log?</strong></a> + + <p>This is a normal message and nothing about which to be + alarmed. It simply means that the client canceled the + connection before it had been completely set up - such as + by the end-user pressing the "Stop" button. People's + patience being what it is, sites with response-time + problems or slow network links may experience this more + than high capacity ones or those with large pipes to the + network.</p> + <hr /> + </li> + + <li> + <a id="wheres-the-dump" name="wheres-the-dump"><strong>The + errorlog says Apache dumped core, but where's the dump + file?</strong></a> + + <p>In Apache version 1.2, the error log message about + dumped core includes the directory where the dump file + should be located. However, many Unixes do not allow a + process that has called <code>setuid()</code> to dump core + for security reasons; the typical Apache setup has the + server started as root to bind to port 80, after which it + changes UIDs to a non-privileged user to serve + requests.</p> + + <p>Dealing with this is extremely operating + system-specific, and may require rebuilding your system + kernel. Consult your operating system documentation or + vendor for more information about whether your system does + this and how to bypass it. If there <em>is</em> a + documented way of bypassing it, it is recommended that you + bypass it only for the <samp>httpd</samp> server process if + possible.</p> + + <p>The canonical location for Apache's core-dump files is + the <a href="../mod/core.html#serverroot">ServerRoot</a> + directory. As of Apache version 1.3, the location can be + set <em>via</em> the <a + href="../mod/core.html#coredumpdirectory"><samp>CoreDumpDirectory</samp></a> + directive to a different directory. Make sure that this + directory is writable by the user the server runs as (as + opposed to the user the server is <em>started</em> as).</p> + <hr /> + </li> + + <li> + <a id="linux-shmget" name="linux-shmget"><strong>When I run + it under Linux I get "shmget: function not found", what + should I do?</strong></a> + + <p>Your kernel has been built without SysV IPC support. You + will have to rebuild the kernel with that support enabled + (it's under the "General Setup" submenu). Documentation for + kernel building is beyond the scope of this FAQ; you should + consult the <a + href="http://www.redhat.com/mirrors/LDP/HOWTO/Kernel-HOWTO.html"> + Kernel HOWTO</a>, or the documentation provided with your + distribution, or a <a + href="http://www.redhat.com/mirrors/LDP/HOWTO/META-FAQ.html"> + Linux newsgroup/mailing list</a>. As a last-resort + workaround, you can comment out the + <code>#define USE_SHMGET_SCOREBOARD</code> definition + in the <samp>LINUX</samp> section of + <samp>src/conf.h</samp> and rebuild the server (prior to + 1.3b4, simply removing + <code>#define HAVE_SHMGET</code> would have sufficed). + This will produce a server which is slower and less + reliable.</p> + <hr /> + </li> + + <li> + <a id="nfslocking" name="nfslocking"><strong>Server hangs, + or fails to start, and/or error log fills with + "<samp>fcntl: F_SETLKW: No record locks available</samp>" + or similar messages</strong></a> + + <p>These are symptoms of a fine locking problem, which + usually means that the server is trying to use a + synchronization file on an NFS filesystem.</p> + + <p>Because of its parallel-operation model, the Apache Web + server needs to provide some form of synchronization when + accessing certain resources. One of these synchronization + methods involves taking out locks on a file, which means + that the filesystem whereon the lockfile resides must + support locking. In many cases this means it <em>can't</em> + be kept on an NFS-mounted filesystem.</p> + + <p>To cause the Web server to work around the NFS locking + limitations, include a line such as the following in your + server configuration files:</p> + + <dl> + <dd><code>LockFile /var/run/apache-lock</code></dd> + </dl> + + <p>The directory should not be generally writable + (<em>e.g.</em>, don't use <samp>/var/tmp</samp>). See the + <a + href="../mod/core.html#lockfile"><samp>LockFile</samp></a> + documentation for more information.</p> + <hr /> + </li> + + <li> + <a id="aixccbug" name="aixccbug"><strong>Why am I getting + "<samp>Expected </Directory> but saw + </Directory></samp>" when I try to start + Apache?</strong></a> + + <p>This is a known problem with certain versions of the AIX + C compiler. IBM are working on a solution, and the issue is + being tracked by <a + href="http://bugs.apache.org/index/full/2312">problem + report #2312</a>.</p> + <hr /> + </li> + + <li> + <a id="redhat" name="redhat"><strong>I'm using RedHat Linux + and I have problems with httpd dying randomly or not + restarting properly</strong></a> + + <p>RedHat Linux versions 4.x (and possibly earlier) RPMs + contain various nasty scripts which do not stop or restart + Apache properly. These can affect you even if you're not + running the RedHat supplied RPMs.</p> + + <p>If you're using the default install then you're probably + running Apache 1.1.3, which is outdated. From RedHat's ftp + site you can pick up a more recent RPM for Apache 1.2.x. + This will solve one of the problems.</p> + + <p>If you're using a custom built Apache rather than the + RedHat RPMs then you should <code>rpm -e apache</code>. In + particular you want the mildly broken + <code>/etc/logrotate.d/apache</code> script to be removed, + and you want the broken <code>/etc/rc.d/init.d/httpd</code> + (or <code>httpd.init</code>) script to be removed. The + latter is actually fixed by the apache-1.2.5 RPMs but if + you're building your own Apache then you probably don't + want the RedHat files.</p> + + <p>We can't stress enough how important it is for folks, + <em>especially vendors</em> to follow the <a + href="../stopping.html">stopping Apache directions</a> + given in our documentation. In RedHat's defense, the broken + scripts were necessary with Apache 1.1.x because the Linux + support in 1.1.x was very poor, and there were various race + conditions on all platforms. None of this should be + necessary with Apache 1.2 and later.</p> + <hr /> + </li> + + <li> + <a id="stopping" name="stopping"><strong>I upgraded from an + Apache version earlier than 1.2.0 and suddenly I have + problems with Apache dying randomly or not restarting + properly</strong></a> + + <p>You should read <a href="#redhat">the previous note</a> + about problems with RedHat installations. It is entirely + likely that your installation has start/stop/restart + scripts which were built for an earlier version of Apache. + Versions earlier than 1.2.0 had various race conditions + that made it necessary to use <code>kill -9</code> at times + to take out all the httpd servers. But that should not be + necessary any longer. You should follow the <a + href="../stopping.html">directions on how to stop and + restart Apache</a>.</p> + + <p>As of Apache 1.3 there is a script + <code>src/support/apachectl</code> which, after a bit of + customization, is suitable for starting, stopping, and + restarting your server.</p> + <hr /> + </li> + + <li> + <a id="setservername" name="setservername"><b>When I try to + start Apache from a DOS window, I get a message like + "<samp>Cannot determine host name. Use ServerName directive + to set it manually.</samp>" What does this mean?</b></a> + + <p>It means what it says; the Apache software can't + determine the hostname of your system. Edit your + <samp>conf\httpd.conf</samp> file, look for the string + "ServerName", and make sure there's an uncommented + directive such as</p> + + <dl> + <dd><code>ServerName localhost</code></dd> + </dl> + + <p>or</p> + + <dl> + <dd><code>ServerName www.foo.com</code></dd> + </dl> + + <p>in the file. Correct it if there one there with wrong + information, or add one if you don't already have one.</p> + + <p>Also, make sure that your Windows system has DNS + enabled. See the TCP/IP setup component of the Networking + or Internet Options control panel.</p> + + <p>After verifying that DNS is enabled and that you have a + valid hostname in your <samp>ServerName</samp> directive, + try to start the server again.</p> + <hr /> + </li> + + <li> + <a id="ws2_32dll" name="ws2_32dll"><b>When I try to start + Apache for Windows, I get a message like "<samp>Unable To + Locate WS2_32.DLL...</samp>". What should I do?</b></a> + + <p>Short answer: You need to install Winsock 2, available + from <a + href="http://www.microsoft.com/windows95/downloads/">http://www.microsoft.com/windows95/downloads/</a></p> + + <p>Detailed answer: Prior to version 1.3.9, Apache for + Windows used Winsock 1.1. Beginning with version 1.3.9, + Apache began using Winsock 2 features (specifically, + WSADuplicateSocket()). WS2_32.DLL implements the Winsock 2 + API. Winsock 2 ships with Windows NT 4.0 and Windows 98. + Some of the earlier releases of Windows 95 did not include + Winsock 2.</p> + <hr /> + </li> + + <li> + <a id="WSADuplicateSocket" + name="WSADuplicateSocket"><b>Apache for Windows does not + start. Error log contains this message: "<samp>[crit] + (10045) The attempted operation is not supported for the + type of object referenced: Parent: WSADuplicateSocket + failed for socket ###</samp>". What does this mean?</b></a> + + + <p>We have seen this problem when Apache is run on systems + along with Virtual Private Networking clients like Aventail + Connect. Aventail Connect is a Layered Service Provider + (LSP) that inserts itself, as a "shim," between the Winsock + 2 API and Window's native Winsock 2 implementation. The + Aventail Connect shim does not implement + WSADuplicateSocket, which is the cause of the failure.</p> + + <p>The shim is not unloaded when Aventail Connect is shut + down. Once observed, the problem persists until the shim is + either explicitly unloaded or the machine is rebooted. + Another potential solution (not tested) is to add + <code>apache.exe</code> to the Aventail "Connect Exclusion + List".</p> + + <p>Apache is affected in a similar way by <em>any</em> + firewall program that isn't correctly configured. Assure + you exclude your Apache server ports (usually port 80) from + the list of ports to block. Refer to your firewall + program's documentation for the how-to.</p> + <hr /> + </li> + + <li> + <a id="err1067" name="err1067"><b>When I try to start + Apache on Windows, I get a message like "<code>System error + 1067 has occurred. The process terminated + unexpectedly</code>." What does this mean?</b></a> + + <p>This message means that the Web server was unable to + start correctly for one reason or another. To find out why, + execute the following commands in a DOS window:</p> +<pre> + c: + cd "\Program Files\Apache Group\Apache" + apache + +</pre> + + <p>(If you don't get the prompt back, hit Control-C to + cause Apache to exit.)</p> + + <p>The error you see will probably be one of those + preceding this question in the FAQ.</p> + + <p>As of Apache 1.3.14, first check the Windows NT Event + Log for Application errors using the Windows NT/2000 Event + Viewer program. Any errors that occur prior to opening the + Apache error log will be stored here, if Apache is run as a + Service on NT or 2000. As with any error, also check your + Apache error log.</p> + <hr /> + </li> + + <li><a id="suseFDN" name="suseFDN"><b>On a SuSE Linux system, I try and + configure access control using basic authentication. + Although I follow the example exactly, authentication + fails, and an error message "<code>admin: not a valid + FDN: ....</code>" is logged.</b></a> + + <p> + In the SuSE distribution, additional 3rd party authentication + modules have been added and activated by default. These modules + interfere with the Apache standard modules and cause Basic + authentication to fail. Our recommendation is to comment all + those modules in <code>/etc/httpd/suse_addmodule.conf</code> + and <code>/etc/httpd/suse_loadmodule.conf</code> which are not + actually required for running your server. + </p><hr /> + </li> + + <li><a id="codered" name="codered"><b>Why do I have weird entries in my + logs asking for <code>default.ida</code> and + <code>cmd.exe</code>?</b></a> + + <p>The host requesting pages from your website and creating + those entries is a Windows machine running IIS that has been + infected by an Internet worm such as Nimda or Code Red. You + can safely ignore these error messages as they do not affect + Apache. ApacheWeek has an <a + href="http://www.apacheweek.com/features/codered">article</a> + with more information.</p><hr /> + </li> + + <li><a id="restart" name="restart"><b>Why am I getting server restart + messages periodically, when I did not restart the server?</b></a> + + <p>Problem: You are noticing restart messages in your error log, + periodically, when you know you did not restart the server + yourself:</p> + +<pre> +[Thu Jun 6 04:02:01 2002] [notice] SIGHUP received. Attempting to restart +[Thu Jun 6 04:02:02 2002] [notice] Apache configured -- resuming normal operations +</pre> + + <p>Check your cron jobs to see when/if your server logs are being + rotated. Compare the time of rotation to the error message time. + If they are the same, you can somewhat safely assume that the + restart is due to your server logs being rotated.</p><hr /> + </li> + + <li><a id="modulemagic" name="modulemagic"><b>Why am I getting + "module <em>module-name</em> is not compatible with this version + of Apache" messages in my error log?</b></a> + + <p>Module Magic Number (MMN) is a constant defined in Apache + source that is associated with binary compatibility of + modules. It is changed when internal Apache structures, + function calls and other significant parts of API change in + such a way that binary compatibility cannot be guaranteed any + more. On MMN change, all third party modules have to be at + least recompiled, sometimes even slightly changed in order + to work with the new version of Apache.</p> + + <p>If you're getting the above error messages, contact the + vendor of the module for the new binary, or compile it if + you have access to the source code.</p><hr /> + </li> + + </ol> + + + </body> +</html> + + + + + + + + + + + + + + + + <h3>E. Configuration Questions</h3> + + <ol> + <li> + <a id="fdlim" name="fdlim"><strong>Why can't I run more + than <<em>n</em>> virtual hosts?</strong></a> + + <p>You are probably running into resource limitations in + your operating system. The most common limitation is the + <em>per</em>-process limit on <strong>file + descriptors</strong>, which is almost always the cause of + problems seen when adding virtual hosts. Apache often does + not give an intuitive error message because it is normally + some library routine (such as <code>gethostbyname()</code>) + which needs file descriptors and doesn't complain + intelligibly when it can't get them.</p> + + <p>Each log file requires a file descriptor, which means + that if you are using separate access and error logs for + each virtual host, each virtual host needs two file + descriptors. Each <a + href="../mod/core.html#listen"><samp>Listen</samp></a> + directive also needs a file descriptor.</p> + + <p>Typical values for <<em>n</em>> that we've seen + are in the neighborhood of 128 or 250. When the server + bumps into the file descriptor limit, it may dump core with + a SIGSEGV, it might just hang, or it may limp along and + you'll see (possibly meaningful) errors in the error log. + One common problem that occurs when you run into a file + descriptor limit is that CGI scripts stop being executed + properly.</p> + + <p>As to what you can do about this:</p> + + <ol> + <li>Reduce the number of <a + href="../mod/core.html#listen"><samp>Listen</samp></a> + directives. If there are no other servers running on the + machine on the same port then you normally don't need any + Listen directives at all. By default Apache listens to + all addresses on port 80.</li> + + <li>Reduce the number of log files. You can use <a + href="../mod/mod_log_config.html"><samp>mod_log_config</samp></a> + to log all requests to a single log file while including + the name of the virtual host in the log file. You can + then write a script to split the logfile into separate + files later if necessary. Such a script is provided with + the Apache 1.3 distribution in the + <samp>src/support/split-logfile</samp> file.</li> + + <li> + Increase the number of file descriptors available to + the server (see your system's documentation on the + <code>limit</code> or <code>ulimit</code> commands). + For some systems, information on how to do this is + available in the <a href="perf.html">performance + hints</a> page. There is a specific note for <a + href="#freebsd-setsize">FreeBSD</a> below. + + <p>For Windows 95, try modifying your + <samp>C:\CONFIG.SYS</samp> file to include a line + like</p> + + <dl> + <dd><code>FILES=300</code></dd> + </dl> + + <p>Remember that you'll need to reboot your Windows 95 + system in order for the new value to take effect.</p> + </li> + + <li>"Don't do that" - try to run with fewer virtual + hosts</li> + + <li>Spread your operation across multiple server + processes (using <a + href="../mod/core.html#listen"><samp>Listen</samp></a> + for example, but see the first point) and/or ports.</li> + </ol> + + <p>Since this is an operating-system limitation, there's + not much else available in the way of solutions.</p> + + <p>As of 1.2.1 we have made attempts to work around various + limitations involving running with many descriptors. <a + href="descriptors.html">More information is + available.</a></p> + <hr /> + </li> + + <li> + <a id="freebsd-setsize" name="freebsd-setsize"><strong>Can + I increase <samp>FD_SETSIZE</samp> on FreeBSD?</strong></a> + + + <p>On versions of FreeBSD before 3.0, the + <samp>FD_SETSIZE</samp> define defaults to 256. This means + that you will have trouble usefully using more than 256 + file descriptors in Apache. This can be increased, but + doing so can be tricky.</p> + + <p>If you are using a version prior to 2.2, you need to + recompile your kernel with a larger + <samp>FD_SETSIZE</samp>. This can be done by adding a line + such as:</p> + + <dl> + <dd><code>options FD_SETSIZE <em>nnn</em></code></dd> + </dl> + + <p>to your kernel config file. Starting at version 2.2, + this is no longer necessary.</p> + + <p>If you are using a version of 2.1-stable from after + 1997/03/10 or 2.2 or 3.0-current from before 1997/06/28, + there is a limit in the resolver library that prevents it + from using more file descriptors than what + <samp>FD_SETSIZE</samp> is set to when libc is compiled. To + increase this, you have to recompile libc with a higher + <samp>FD_SETSIZE</samp>.</p> + + <p>In FreeBSD 3.0, the default <samp>FD_SETSIZE</samp> has + been increased to 1024 and the above limitation in the + resolver library has been removed.</p> + + <p>After you deal with the appropriate changes above, you + can increase the setting of <samp>FD_SETSIZE</samp> at + Apache compilation time by adding + "<samp>-DFD_SETSIZE=<em>nnn</em></samp>" to the + <samp>EXTRA_CFLAGS</samp> line in your + <samp>Configuration</samp> file.</p> + <hr /> + </li> + + <li> + <a id="errordoc401" name="errordoc401"><strong>Why doesn't + my <code>ErrorDocument 401</code> work?</strong></a> + + <p>You need to use it with a URL in the form + "<samp>/foo/bar</samp>" and not one with a method and + hostname such as "<samp>http://host/foo/bar</samp>". See + the <a + href="../mod/core.html#errordocument"><samp>ErrorDocument</samp></a> + documentation for details. This was incorrectly documented + in the past.</p> + <hr /> + </li> + + <li> + <a id="cookies1" name="cookies1"><strong>Why does Apache + send a cookie on every response?</strong></a> + + <p>Apache does <em>not</em> automatically send a cookie on + every response, unless you have re-compiled it with the <a + href="../mod/mod_usertrack.html"><samp>mod_usertrack</samp></a> + module, and specifically enabled it with the <a + href="../mod/mod_usertrack.html#cookietracking"><samp>CookieTracking</samp></a> + directive. This module has been in Apache since version + 1.2. This module may help track users, and uses cookies to + do this. If you are not using the data generated by + <samp>mod_usertrack</samp>, do not compile it into + Apache.</p> + <hr /> + </li> + + <li> + <a id="cookies2" name="cookies2"><strong>Why don't my + cookies work, I even compiled in + <samp>mod_cookies</samp>?</strong></a> + + <p>Firstly, you do <em>not</em> need to compile in + <samp>mod_cookies</samp> in order for your scripts to work + (see the <a href="#cookies1">previous question</a> for more + about <samp>mod_cookies</samp>). Apache passes on your + <samp>Set-Cookie</samp> header fine, with or without this + module. If cookies do not work it will be because your + script does not work properly or your browser does not use + cookies or is not set-up to accept them.</p> + <hr /> + </li> + + <li> + <a id="jdk1-and-http1.1" + name="jdk1-and-http1.1"><strong>Why do my Java app[let]s + give me plain text when I request an URL from an Apache + server?</strong></a> + + <p>As of version 1.2, Apache is an HTTP/1.1 (HyperText + Transfer Protocol version 1.1) server. This fact is + reflected in the protocol version that's included in the + response headers sent to a client when processing a + request. Unfortunately, low-level Web access classes + included in the Java Development Kit (JDK) version 1.0.2 + expect to see the version string "HTTP/1.0" and do not + correctly interpret the "HTTP/1.1" value Apache is sending + (this part of the response is a declaration of what the + server can do rather than a declaration of the dialect of + the response). The result is that the JDK methods do not + correctly parse the headers, and include them with the + document content by mistake.</p> + + <p>This is definitely a bug in the JDK 1.0.2 foundation + classes from Sun, and it has been fixed in version 1.1. + However, the classes in question are part of the virtual + machine environment, which means they're part of the Web + browser (if Java-enabled) or the Java environment on the + client system - so even if you develop <em>your</em> + classes with a recent JDK, the eventual users might + encounter the problem. The classes involved are replaceable + by vendors implementing the Java virtual machine + environment, and so even those that are based upon the + 1.0.2 version may not have this problem.</p> + + <p>In the meantime, a workaround is to tell Apache to + "fake" an HTTP/1.0 response to requests that come from the + JDK methods; this can be done by including a line such as + the following in your server configuration files:</p> + + <dl> + <dd><code>BrowserMatch Java1.0 force-response-1.0<br /> + BrowserMatch JDK/1.0 force-response-1.0</code></dd> + </dl> + + <p>More information about this issue can be found in the <a + href="http://httpd.apache.org/info/jdk-102.html"><cite>Java + and HTTP/1.1</cite></a> page at the Apache web site.</p> + <hr /> + </li> + + <li> + <a id="midi" name="midi"><strong>How do I get Apache to + send a MIDI file so the browser can play it?</strong></a> + + <p>Even though the registered MIME type for MIDI files is + <samp>audio/midi</samp>, some browsers are not set up to + recognize it as such; instead, they look for + <samp>audio/x-midi</samp>. There are two things you can do + to address this:</p> + + <ol> + <li>Configure your browser to treat documents of type + <samp>audio/midi</samp> correctly. This is the type that + Apache sends by default. This may not be workable, + however, if you have many client installations to change, + or if some or many of the clients are not under your + control.</li> + + <li> + Instruct Apache to send a different + <samp>Content-type</samp> header for these files by + adding the following line to your server's + configuration files: + + <dl> + <dd><code>AddType audio/x-midi .mid .midi + .kar</code></dd> + </dl> + + <p>Note that this may break browsers that <em>do</em> + recognize the <samp>audio/midi</samp> MIME type unless + they're prepared to also handle + <samp>audio/x-midi</samp> the same way.</p> + </li> + </ol> + <hr /> + </li> + + <li> + <a id="addlog" name="addlog"><strong>How do I add browsers + and referrers to my logs?</strong></a> + + <p>Apache provides a couple of different ways of doing + this. The recommended method is to compile the <a + href="../mod/mod_log_config.html"><samp>mod_log_config</samp></a> + module into your configuration and use the <a + href="../mod/mod_log_config.html#customlog"><samp>CustomLog</samp></a> + directive.</p> + + <p>You can either log the additional information in files + other than your normal transfer log, or you can add them to + the records already being written. For example:</p> + + <p> + <code>CustomLog logs/access_log "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\""</code></p> + + <p>This will add the values of the <samp>User-agent:</samp> + and <samp>Referer:</samp> headers, which indicate the + client and the referring page, respectively, to the end of + each line in the access log.</p> + + <p>You may want to check out the <cite>Apache Week</cite> + article entitled: "<a + href="http://www.apacheweek.com/features/logfiles" + rel="Help"><cite>Gathering Visitor Information: Customizing + Your Logfiles</cite></a>".</p> + <hr /> + </li> + + <li> + <a id="set-servername" name="set-servername"><strong>Why + does accessing directories only work when I include the + trailing "/" + (<em>e.g.</em>, <samp>http://foo.domain.com/~user/</samp>) + but not when I omit it + (<em>e.g.</em>, <samp>http://foo.domain.com/~user</samp>)?</strong></a> + + + <p>When you access a directory without a trailing "/", + Apache needs to send what is called a redirect to the + client to tell it to add the trailing slash. If it did not + do so, relative URLs would not work properly. When it sends + the redirect, it needs to know the name of the server so + that it can include it in the redirect. There are two ways + for Apache to find this out; either it can guess, or you + can tell it. If your DNS is configured correctly, it can + normally guess without any problems. If it is not, however, + then you need to tell it.</p> + + <p>Add a <a + href="../mod/core.html#servername">ServerName</a> directive + to the config file to tell it what the domain name of the + server is.</p> + + <p>The other thing that can occasionally cause this symptom is a + misunderstanding of the <a + href="../mod/mod_alias.html#alias">Alias</a> directive, + resulting in an alias working with a trailing slash, and not + without one. The <code>Alias</code> directive is very literal, + and aliases what you tell it to. Consider the following + example:</p> + + <pre> + Alias /example/ /home/www/example/ + </pre> + + <p>The above directive creates an alias for URLs starting with + <code>/example/</code>, but does <em>not</em> alias URLs + starting with <code>/example</code>. That is to say, a URL such + as <code>http://servername.com/example/</code> will get the + desired content, but a URL such as + <code>http://servername.com/example</code> will result in a + "file not found" error.</p> + + <p>The following <code>Alias</code>, on the other hand, will + work for both cases:</p> + + <pre> + Alias /example /home/www/example + </pre> + + <hr /> + </li> + + <li> + <a id="no-info-directives" + name="no-info-directives"><strong>Why doesn't mod_info list + any directives?</strong></a> + + <p>The <a + href="../mod/mod_info.html"><samp>mod_info</samp></a> + module allows you to use a Web browser to see how your + server is configured. Among the information it displays is + the list modules and their configuration directives. The + "current" values for the directives are not necessarily + those of the running server; they are extracted from the + configuration files themselves at the time of the request. + If the files have been changed since the server was last + reloaded, the display will not match the values actively in + use. If the files and the path to the files are not + readable by the user as which the server is running (see + the <a href="../mod/core.html#user"><samp>User</samp></a> + directive), then <samp>mod_info</samp> cannot read them in + order to list their values. An entry <em>will</em> be made + in the error log in this event, however.</p> + <hr /> + </li> + + <li> + <a id="namevhost" name="namevhost"><strong>I upgraded to + Apache 1.3 and now my virtual hosts don't + work!</strong></a> + + <p>In versions of Apache prior to 1.3b2, there was a lot of + confusion regarding address-based virtual hosts and + (HTTP/1.1) name-based virtual hosts, and the rules + concerning how the server processed + <samp><VirtualHost></samp> definitions were very + complex and not well documented.</p> + + <p>Apache 1.3b2 introduced a new directive, <a + href="../mod/core.html#namevirtualhost"><samp>NameVirtualHost</samp></a>, + which simplifies the rules quite a bit. However, changing + the rules like this means that your existing name-based + <samp><VirtualHost></samp> containers probably won't + work correctly immediately following the upgrade.</p> + + <p>To correct this problem, add the following line to the + beginning of your server configuration file, before + defining any virtual hosts:</p> + + <dl> + <dd><code>NameVirtualHost <em>n.n.n.n</em></code></dd> + </dl> + + <p>Replace the "<samp>n.n.n.n</samp>" with the IP address + to which the name-based virtual host names resolve; if you + have multiple name-based hosts on multiple addresses, + repeat the directive for each address.</p> + + <p>Make sure that your name-based + <samp><VirtualHost></samp> blocks contain + <samp>ServerName</samp> and possibly + <samp>ServerAlias</samp> directives so Apache can be sure + to tell them apart correctly.</p> + + <p>Please see the <a href="../vhosts/">Apache Virtual Host + documentation</a> for further details about + configuration.</p> + <hr /> + </li> + + <li> + <a id="redhat-htm" name="redhat-htm"><strong>I'm using + RedHat Linux and my .htm files are showing up as HTML + source rather than being formatted!</strong></a> + + <p>RedHat messed up and forgot to put a content type for + <code>.htm</code> files into <code>/etc/mime.types</code>. + Edit <code>/etc/mime.types</code>, find the line containing + <code>html</code> and add <code>htm</code> to it. Then + restart your httpd server:</p> + + <dl> + <dd><code>kill -HUP `cat /var/run/httpd.pid`</code></dd> + </dl> + + <p>Then <strong>clear your browsers' caches</strong>. (Many + browsers won't re-examine the content type after they've + reloaded a page.)</p> + <hr /> + </li> + + <li> + <a id="htaccess-work" name="htaccess-work"><strong>My + <code>.htaccess</code> files are being + ignored.</strong></a> + + <p>This is almost always due to your <a + href="../mod/core.html#allowoverride">AllowOverride</a> + directive being set incorrectly for the directory in + question. If it is set to <code>None</code> then .htaccess + files will not even be looked for. If you do have one that + is set, then be certain it covers the directory you are + trying to use the .htaccess file in. This is normally + accomplished by ensuring it is inside the proper <a + href="../mod/core.html#directory">Directory</a> + container.</p> + <hr /> + </li> + + <li> + <a id="forbidden" name="forbidden"><strong>Why do I get a + "<samp>Forbidden</samp>" message whenever I try to access a + particular directory?</strong></a> + + <p>This message is generally caused because either</p> + + <ul> + <li>The underlying file system permissions do not allow + the User/Group under which Apache is running to access + the necessary files; or</li> + + <li>The Apache configuration has some access restrictions + in place which forbid access to the files.</li> + </ul> + + <p>You can determine which case applies to your situation + by checking the error log.</p> + + <p>In the case where file system permission are at fault, + remember that not only must the directory and files in + question be readable, but also all parent directories must + be at least searchable by the web server in order for the + content to be accessible.</p> + <hr /> + </li> + + <li> + <a id="malfiles" name="malfiles"><b>Why do I get a + "<samp>Forbidden/You don't have permission to access / on + this server</samp>" message whenever I try to access my + server?</b></a> + + <p>Search your <code>conf/httpd.conf</code> file for this + exact string: <code><Files ~></code>. If you find it, + that's your problem -- that particular <Files> + container is malformed. Delete it or replace it with + <code><Files ~ "^\.ht"></code> and restart your + server and things should work as expected.</p> + + <p>This error appears to be caused by a problem with the + version of linuxconf distributed with Redhat 6.x. It may + reappear if you use linuxconf again.</p> + + <p>If you don't find this string, check out the <a + href="#forbidden">previous question</a>.</p> + <hr /> + </li> + + <li> + <a id="ie-ignores-mime" name="ie-ignores-mime"><strong>Why + do my files appear correctly in Internet Explorer, but show + up as source or trigger a save window with + Netscape; or, Why doesn't Internet Explorer render + my text/plain document correctly?</strong></a> + + <p>MS Internet Explorer (MSIE) and Netscape handle mime type + detection in different ways, and therefore will display the + document differently. In particular, IE sometimes relies on + the file extension or the contents of the file to determine + the mime type. This can happen when the server specifies a + mime type of <code>application/octet-stream</code> or + <code>text/plain</code>. This behavior violates the the HTTP + standard and makes it impossible to deliver plain text + documents to MSIE clients in some cases. More details are + available on MSIE's mime type detection behavior in an <a + href="http://msdn.microsoft.com/workshop/networking/moniker/overview/appendix_a.asp"> + MSDN article</a> and a <a + href="http://ppewww.ph.gla.ac.uk/~flavell/www/content-type.html">note</a> + by Alan J. Flavell.</p> + + <p>The best you can do as a server administrator is to + accurately configure the mime type of your documents by editing + the <code>mime.types</code> file or using an <a + href="../mod/mod_mime.html#addtype"><code>AddType</code></a> + directive in the Apache configuration files. In some cases, + you may be able to fool MSIE into rendering text/plain documents + correctly by assuring they have a <code>.txt</code> filename + extension, but this will not work if MSIE thinks the content + looks like another file type. +</p> <hr /> + </li> + <li> + <a name="canonical-hostnames"><strong>My site is accessible + under many different hostnames; how do I redirect clients + so that they see only a single name?</strong></a> + + <p>Many sites map a variety of hostnames to the same content. + For example, <code>www.example.com</code>, + <code>example.com</code> and <code>www.example.net</code> may + all refer to the same site. It is best to make sure that, + regardless of the name clients use to access the site, they + will be redirected to a single, canonical hostname. This + makes the site easier to maintain and assures that there will + be only one version of the site in proxy caches and search + engines.</p> + + <p>There are two techniques to implement canonical hostnames:</p> + + <ol> + <li>Use <a href="../mod/mod_rewrite.html">mod_rewrite</a> + as described in the "Canonical Hostnames" section of the + <a href="rewriteguide.html">URL Rewriting Guide</a>.</li> + + <li>Use <a href="../vhosts/name-based.html">name-based + virtual hosting</a>: + +<blockquote><code> +NameVirtualHost *<br /> +<br /> +<VirtualHost *><br /> + ServerName www.example.net<br /> + ServerAlias example.com<br /> + Redirect permanent / http://www.example.com/<br /> +</VirtualHost><br /> +<br /> +<VirtualHost *><br /> + ServerName www.example.com<br /> + DocumentRoot /usr/local/apache/htdocs<br /> +</VirtualHost> +</code></blockquote> + </li></ol> + <hr /></li> + + <li><a id="firewall" name="firewall"><strong>Why can I access my + website from the server or from my local network, but I + can't access it from elsewhere on the Internet?</strong></a> + + <p>There are many possible reasons for this, and almost all + of them are related to the configuration of your network, not + the configuration of the Apache HTTP Server. One of the most + common problems is that a firewall blocks access to the + default HTTP port 80. In particular, many consumer ISPs + block access to this port. You can see if this is the case + by changing any <code>Port</code> and <code>Listen</code> + directives in <code>httpd.conf</code> to use port 8000 and + then request your site using + <code>http://yourhost.example.com:8000/</code>. (Of course, + a very restrictive firewall may block this port as well.)</p> + + <hr /></li> + + <li><a id="indexes" name="indexes"><strong>How do I turn automatic + directory listings on or off?</strong></a> + + <p>If a client requests a URL that designates a directory and + the directory does not contain a filename that matches the <a + href="../mod/mod_dir.html#directoryindex">DirectoryIndex</a> + directive, then <a + href="../mod/mod_autoindex.html">mod_autoindex</a> can be + configured to present a listing of the directory contents.</p> + + <p>To turn on automatic directory indexing, find the + <a href="../mod/core.html#options">Options</a> directive that + applies to the directory and add the <code>Indexes</code> + keyword. For example:</p> + + <blockquote><code> + <Directory /path/to/directory><br /> + Options +Indexes<br /> + </Directory> + </code></blockquote> + + <p>To turn off automatic directory indexing, remove + the <code>Indexes</code> keyword from the appropriate + <code>Options</code> line. To turn off directory listing + for a particular subdirectory, you can use + <code>Options -Indexes</code>. For example:</p> + + <blockquote><code> + <Directory /path/to/directory><br /> + Options -Indexes<br /> + </Directory> + </code></blockquote> + + <hr /></li> + + <li><a id="options" name="options"><strong>Why do my Options + directives not have the desired effect?</strong></a> + + <p>Directives placed in the configuration files are applied + in a very particular order, as described by <a + href="../sections.html">How Directory, Location, and Files + sections work</a>. In addition, each <a + href="../mod/core.html#options">Options</a> directive has the + effect of resetting the options to <code>none</code> before + adding the specified options (unless only "+" and "-" options + are used). The consequence is that <code>Options</code> set + in the main server or virtual host context (outside any + directory, location, or files section) will usually have no + effect, because they are overridden by more specific + <code>Options</code> directives. For example, in the following</p> + +<blockquote><code> +<Directory /usr/local/apache/htdocs><br /> + Options Indexes<br /> +</Directory><br /> +Options Includes ExecCGI<br /> +</code></blockquote> + + <p><code>Includes</code> and <code>ExecCGI</code> will be + <strong>off</strong> in the <code>/usr/local/apache/htdocs</code> + directory.</p> + + <p>You can usually avoid problems by either finding the + <code>Options</code> directive that already applies to a + specific directory and changing it, or by putting your + <code>Options</code> directive inside the most specific possible + <code><Directory></code> section.</p> + + <hr /></li> + + + <li><a id="serverheader" name="serverheader"><strong>How can I change + the information that Apache returns about itself in the + headers?</strong></a> + + <p>When a client connects to Apache, part of the information returned in + the headers is the name "Apache" Additional information that can be sent + is the version number, such as "1.3.26", the operating system, and a + list of non-standard modules you have installed.</p> + + <p>For example:</p> + +<blockquote><code> +Server: Apache/1.3.26 (Unix) mod_perl/1.26 +</code></blockquote> + + <p>Frequently, people want to remove this information, under the mistaken + understanding that this will make the system more secure. This is + probably not the case, as the same exploits will likely be attempted + regardless of the header information you provide.</p> + + <p>There are, however, two answers to this question: the correct answer, + and the answer that you are probably looking for.</p> + + <p>The correct answer to this question is that you should use the + ServerTokens directive to alter the quantity of information which is + passed in the headers. Setting this directive to <code>Prod</code> will + pass the least possible amount of information:</p> + +<blockquote><code> +Server: Apache +</code></blockquote> + + <p>The answer you are probably looking for is how to make Apache lie + about what what it is, ie send something like:</p> + +<blockquote><code> +Server: Bob's Happy HTTPd Server +</code></blockquote> + + <p>In order to do this, you will need to modify the Apache source code and + rebuild Apache. This is not advised, as it is almost certain not to + provide you with the added security you think that you are gaining. The + exact method of doing this is left as an exercise for the reader, as we + are not keen on helping you do something that is intrinsically a bad + idea.</p> + + <hr /></li> + + <li><a id="proxyscan" name="proxyscan"><strong>Why do I see requests + for other sites appearing in my log files?</strong></a> + + <p>A an access_log entry showing this situation could look + like this:</p> + + <blockquote><code> 63.251.56.142 - - + [25/Jul/2002:12:48:04 -0700] "GET http://www.yahoo.com/ + HTTP/1.0" 200 1456 </code></blockquote> + + <p>The question is: why did a request for + <code>www.yahoo.com</code> come to your server instead of + Yahoo's server? And why does the response have a status + code of 200 (success)?</p> + + <p>This is usually the result of malicious clients trying to + exploit open proxy servers to access a website without + revealing their true location. If you find entries like this + in your log, the first thing to do is to make sure you have + properly configured your server not to proxy for unknown + clients. If you don't need to provide a proxy server at all, + you should simply assure that the <a + href="../mod/mod_proxy.html#proxyrequests">ProxyRequests</a> + directive is <strong>not</strong> set <code>on</code>. + If you do need to run a proxy server, then you must ensure + that you <a href="../mod/mod_proxy.html#access">secure your + server properly</a> so that only authorized clients can use + it.</p> + + <p>If your server is configured properly, then the attempt to + proxy through your server will fail. If you see a status + code of <code>404</code> (file not found) in the log, then + you know that the request failed. If you see a status code + of <code>200</code> (success), that does not necessarily mean + that the attempt to proxy succeeded. RFC2616 section 5.1.2 + mandates that Apache must accept requests with absolute URLs + in the request-URI, even for non-proxy requests. Since + Apache has no way to know all the different names that your + server may be known under, it cannot simply reject hostnames + it does not recognize. Instead, it will serve requests for + unknown sites locally by stripping off the hostname and using + the default server or virtual host. Therefore you can + compare the size of the file (1456 in the above example) to + the size of the corresponding file in your default server. + If they are the same, then the proxy attempt failed, since a + document from your server was delivered, not a document from + <code>www.yahoo.com</code>.</p> + + <p>If you wish to prevent this type of request entirely, then + you need to let Apache know what hostnames to accept and what + hostnames to reject. You do this by configuring name-virtual + hosts, where the first listed host is the default host that + will catch and reject unknown hostnames. For example:</p> + +<blockquote> +<pre> +NameVirtualHost * + +<VirtualHost *> + ServerName default.only + <Location /> + Order allow,deny + Deny from all + </Location> +</VirtualHost> + +<VirtualHost *> + ServerName realhost1.example.com + ServerAlias alias1.example.com alias2.example.com + DocumentRoot /path/to/site1 +</VirtualHost> + +... +</pre> +</blockquote> + <hr /></li> + + </ol> + + + </body> +</html> + + + + + + + + + + + + + + + + <h3>F. Dynamic Content (CGI and SSI)</h3> + + <ol> + <li> + <a id="CGIoutsideScriptAlias" + name="CGIoutsideScriptAlias"><strong>How do I enable CGI + execution in directories other than the + ScriptAlias?</strong></a> + + <p>Apache recognizes all files in a directory named as a <a + href="../mod/mod_alias.html#scriptalias"><samp>ScriptAlias</samp></a> + as being eligible for execution rather than processing as + normal documents. This applies regardless of the file name, + so scripts in a ScriptAlias directory don't need to be + named "<samp>*.cgi</samp>" or "<samp>*.pl</samp>" or + whatever. In other words, <em>all</em> files in a + ScriptAlias directory are scripts, as far as Apache is + concerned.</p> + + <p>To persuade Apache to execute scripts in other + locations, such as in directories where normal documents + may also live, you must tell it how to recognize them - and + also that it's okay to execute them. For this, you need to + use something like the <a + href="../mod/mod_mime.html#addhandler"><samp>AddHandler</samp></a> + directive.</p> + + <ol> + <li> + In an appropriate section of your server configuration + files, add a line such as + + <dl> + <dd><code>AddHandler cgi-script .cgi</code></dd> + </dl> + + <p>The server will then recognize that all files in + that location (and its logical descendants) that end in + "<samp>.cgi</samp>" are script files, not + documents.</p> + </li> + + <li>Make sure that the directory location is covered by + an <a + href="../mod/core.html#options"><samp>Options</samp></a> + declaration that includes the <samp>ExecCGI</samp> + option.</li> + </ol> + + <p>In some situations, you might not want to actually allow + all files named "<samp>*.cgi</samp>" to be executable. + Perhaps all you want is to enable a particular file in a + normal directory to be executable. This can be + alternatively accomplished <em>via</em> <a + href="../mod/mod_rewrite.html"><samp>mod_rewrite</samp></a> + and the following steps:</p> + + <ol> + <li> + Locally add to the corresponding <samp>.htaccess</samp> + file a ruleset similar to this one: + + <dl> + <dd><code>RewriteEngine on<br /> + RewriteBase /~foo/bar/<br /> + RewriteRule ^quux\.cgi$ - + [T=application/x-httpd-cgi]</code></dd> + </dl> + </li> + + <li>Make sure that the directory location is covered by + an <a + href="../mod/core.html#options"><samp>Options</samp></a> + declaration that includes the <samp>ExecCGI</samp> and + <samp>FollowSymLinks</samp> option.</li> + </ol> + <hr /> + </li> + + <li> + <a id="premature-script-headers" + name="premature-script-headers"><strong>What does it mean + when my CGIs fail with "<samp>Premature end of script + headers</samp>"?</strong></a> + + <p>It means just what it says: the server was expecting a + complete set of HTTP headers (one or more followed by a + blank line), and didn't get them.</p> + + <p>The most common cause of this problem is the script + dying before sending the complete set of headers, or + possibly any at all, to the server. To see if this is the + case, try running the script standalone from an interactive + session, rather than as a script under the server. If you + get error messages, this is almost certainly the cause of + the "premature end of script headers" message. Even if the + CGI runs fine from the command line, remember that the + environment and permissions may be different when running + under the web server. The CGI can only access resources + allowed for the <a + href="../mod/core.html#user"><code>User</code></a> and <a + href="../mod/core.html#group"><code>Group</code></a> + specified in your Apache configuration. In addition, the + environment will not be the same as the one provided on the + command line, but it can be adjusted using the directives + provided by <a href="../mod/mod_env.html">mod_env</a>.</p> + + <p>The second most common cause of this (aside from people + not outputting the required headers at all) is a result of + an interaction with Perl's output buffering. To make Perl + flush its buffers after each output statement, insert the + following statements around the <code>print</code> or + <code>write</code> statements that send your HTTP + headers:</p> + + <dl> + <dd><code>{<br /> + local ($oldbar) = $|;<br /> + $cfh = select (STDOUT);<br /> + $| = 1;<br /> + #<br /> + # print your HTTP headers here<br /> + #<br /> + $| = $oldbar;<br /> + select ($cfh);<br /> + }</code></dd> + </dl> + + <p>This is generally only necessary when you are calling + external programs from your script that send output to + stdout, or if there will be a long delay between the time + the headers are sent and the actual content starts being + emitted. To maximize performance, you should turn + buffer-flushing back <em>off</em> (with <code>$| = 0</code> + or the equivalent) after the statements that send the + headers, as displayed above.</p> + + <p>If your script isn't written in Perl, do the equivalent + thing for whatever language you <em>are</em> using + (<em>e.g.</em>, for C, call <code>fflush()</code> after + writing the headers).</p> + + <p>Another cause for the "premature end of script headers" + message are the RLimitCPU and RLimitMEM directives. You may + get the message if the CGI script was killed due to a + resource limit.</p> + + <p>In addition, a configuration problem in <a + href="../suexec.html">suEXEC</a>, mod_perl, or another + third party module can often interfere with the execution + of your CGI and cause the "premature end of script headers" + message.</p> + <hr /> + </li> + + <li> + <a id="POSTnotallowed" name="POSTnotallowed"><strong>Why do + I keep getting "Method Not Allowed" for form POST + requests?</strong></a> + + <p>This is almost always due to Apache not being configured + to treat the file you are trying to POST to as a CGI + script. You can not POST to a normal HTML file; the + operation has no meaning. See the FAQ entry on <a + href="#CGIoutsideScriptAlias">CGIs outside ScriptAliased + directories</a> for details on how to configure Apache to + treat the file in question as a CGI.</p> + <hr /> + </li> + + <li> + <a id="nph-scripts" name="nph-scripts"><strong>How can I + get my script's output without Apache buffering it? Why + doesn't my server push work?</strong></a> + + <p>As of Apache 1.3, CGI scripts are essentially not + buffered. Every time your script does a "flush" to output + data, that data gets relayed on to the client. Some + scripting languages, for example Perl, have their own + buffering for output - this can be disabled by setting the + <code>$|</code> special variable to 1. Of course this does + increase the overall number of packets being transmitted, + which can result in a sense of slowness for the end + user.</p> + + <p>Prior to 1.3, you needed to use "nph-" scripts to + accomplish non-buffering. Today, the only difference + between nph scripts and normal scripts is that nph scripts + require the full HTTP headers to be sent.</p> + <hr /> + </li> + + <li> + <a id="cgi-spec" name="cgi-spec"><strong>Where can I find + the "CGI specification"?</strong></a> + + <p>The Common Gateway Interface (CGI) specification can be + found at the original NCSA site < <a + href="http://hoohoo.ncsa.uiuc.edu/cgi/interface.html"><samp> + http://hoohoo.ncsa.uiuc.edu/cgi/interface.html</samp></a>>. + This version hasn't been updated since 1995, and there have + been some efforts to update it.</p> + + <p>A new draft is being worked on with the intent of making + it an informational RFC; you can find out more about this + project at <<a + href="http://web.golux.com/coar/cgi/"><samp>http://web.golux.com/coar/cgi/</samp></a>>.</p> + <hr /> + </li> + + <li> + <a id="fastcgi" name="fastcgi"><strong>Why isn't FastCGI + included with Apache any more?</strong></a> + + <p>The simple answer is that it was becoming too difficult + to keep the version being included with Apache synchronized + with the master copy at the <a + href="http://www.fastcgi.com/">FastCGI web site</a>. When a + new version of Apache was released, the version of the + FastCGI module included with it would soon be out of + date.</p> + + <p>You can still obtain the FastCGI module for Apache from + the master FastCGI web site.</p> + <hr /> + </li> + + <li> + <a id="ssi-part-i" name="ssi-part-i"><strong>How do I + enable SSI (parsed HTML)?</strong></a> + + <p>SSI (an acronym for Server-Side Include) directives + allow static HTML documents to be enhanced at run-time + (<em>e.g.</em>, when delivered to a client by Apache). The + format of SSI directives is covered in the <a + href="../mod/mod_include.html">mod_include manual</a>; + suffice it to say that Apache supports not only SSI but + xSSI (eXtended SSI) directives.</p> + + <p>Processing a document at run-time is called + <em>parsing</em> it; hence the term "parsed HTML" sometimes + used for documents that contain SSI instructions. Parsing + tends to be resource-consumptive compared to serving static + files, and is not enabled by default. It can also interfere + with the cachability of your documents, which can put a + further load on your server. (See the <a + href="#ssi-part-ii">next question</a> for more information + about this.)</p> + + <p>To enable SSI processing, you need to</p> + + <ul> + <li>Build your server with the <a + href="../mod/mod_include.html"><samp>mod_include</samp></a> + module. This is normally compiled in by default.</li> + + <li>Make sure your server configuration files have an <a + href="../mod/core.html#options"><samp>Options</samp></a> + directive which permits <samp>Includes</samp>.</li> + + <li> + Make sure that the directory where you want the SSI + documents to live is covered by the "server-parsed" + content handler, either explicitly or in some ancestral + location. That can be done with the following <a + href="../mod/mod_mime.html#addhandler"><samp>AddHandler</samp></a> + directive: + + <dl> + <dd><code>AddHandler server-parsed .shtml</code></dd> + </dl> + + <p>This indicates that all files ending in ".shtml" in + that location (or its descendants) should be parsed. + Note that using ".html" will cause all normal HTML + files to be parsed, which may put an inordinate load on + your server.</p> + </li> + </ul> + + <p>For additional information, see the <cite>Apache + Week</cite> article on <a + href="http://www.apacheweek.com/features/ssi" + rel="Help"><cite>Using Server Side Includes</cite></a>.</p> + <hr /> + </li> + + <li> + <a id="ssi-part-ii" name="ssi-part-ii"><strong>Why don't my + parsed files get cached?</strong></a> + + <p>Since the server is performing run-time processing of + your SSI directives, which may change the content shipped + to the client, it can't know at the time it starts parsing + what the final size of the result will be, or whether the + parsed result will always be the same. This means that it + can't generate <samp>Content-Length</samp> or + <samp>Last-Modified</samp> headers. Caches commonly work by + comparing the <samp>Last-Modified</samp> of what's in the + cache with that being delivered by the server. Since the + server isn't sending that header for a parsed document, + whatever's doing the caching can't tell whether the + document has changed or not - and so fetches it again to be + on the safe side.</p> + + <p>You can work around this in some cases by causing an + <samp>Expires</samp> header to be generated. (See the <a + href="../mod/mod_expires.html" + rel="Help"><samp>mod_expires</samp></a> documentation for + more details.) Another possibility is to use the <a + href="../mod/mod_include.html#xbithack" + rel="Help"><samp>XBitHack Full</samp></a> mechanism, which + tells Apache to send (under certain circumstances detailed + in the XBitHack directive description) a + <samp>Last-Modified</samp> header based upon the last + modification time of the file being parsed. Note that this + may actually be lying to the client if the parsed file + doesn't change but the SSI-inserted content does; if the + included content changes often, this can result in stale + copies being cached.</p> + <hr /> + </li> + + <li> + <a id="ssi-part-iii" name="ssi-part-iii"><strong>How can I + have my script output parsed?</strong></a> + + <p>So you want to include SSI directives in the output from + your CGI script, but can't figure out how to do it? The + short answer is "you can't." This is potentially a security + liability and, more importantly, it can not be cleanly + implemented under the current server API. The best + workaround is for your script itself to do what the SSIs + would be doing. After all, it's generating the rest of the + content.</p> + + <p>This is a feature The Apache Group hopes to add in the + next major release after 1.3.</p> + <hr /> + </li> + + <li> + <a id="ssi-part-iv" name="ssi-part-iv"><strong>SSIs don't + work for VirtualHosts and/or user home + directories.</strong></a> + + <p>This is almost always due to having some setting in your + config file that sets "Options Includes" or some other + setting for your DocumentRoot but not for other + directories. If you set it inside a Directory section, then + that setting will only apply to that directory.</p> + <hr /> + </li> + + <li> + <a id="errordocssi" name="errordocssi"><strong>How can I + use <code>ErrorDocument</code> and SSI to simplify + customized error messages?</strong></a> + + <p>Have a look at <a href="custom_errordocs.html">this + document</a>. It shows in example form how you can a + combination of XSSI and negotiation to tailor a set of + <code>ErrorDocument</code>s to your personal taste, and + returning different internationalized error responses based + on the client's native language.</p> + <hr /> + </li> + + <li> + <a id="remote-user-var" name="remote-user-var"><strong>Why + is the environment variable <samp>REMOTE_USER</samp> not + set?</strong></a> + + <p>This variable is set and thus available in SSI or CGI + scripts <strong>if and only if</strong> the requested + document was protected by access authentication. For an + explanation on how to implement these restrictions, see <a + href="http://www.apacheweek.com/"><cite>Apache + Week</cite></a>'s articles on <a + href="http://www.apacheweek.com/features/userauth"><cite>Using + User Authentication</cite></a> or <a + href="http://www.apacheweek.com/features/dbmauth"><cite>DBM + User Authentication</cite></a>.</p> + + <p>Hint: When using a CGI script to receive the data of a + HTML <samp>FORM</samp> notice that protecting the document + containing the <samp>FORM</samp> is not sufficient to + provide <samp>REMOTE_USER</samp> to the CGI script. You + have to protect the CGI script, too. Or alternatively only + the CGI script (then authentication happens only after + filling out the form).</p> + <hr /> + </li> + + <li> + <a id="user-cgi" name="user-cgi"><strong>How do I allow + each of my user directories to have a cgi-bin + directory?</strong></a> + + <p>Remember that CGI execution does not need to be + restricted only to cgi-bin directories. You can <a + href="#CGIoutsideScriptAlias">allow CGI script execution in + arbitrary parts of your filesystem</a>.</p> + + <p>There are many ways to give each user directory a + cgi-bin directory such that anything requested as + <samp>http://example.com/~user/cgi-bin/program</samp> will + be executed as a CGI script. Two alternatives are:</p> + + <ol> + <li> + Place the cgi-bin directory next to the public_html + directory: + + <dl> + <dd><code>ScriptAliasMatch ^/~([^/]*)/cgi-bin/(.*) + /home/$1/cgi-bin/$2</code></dd> + </dl> + </li> + + <li> + Place the cgi-bin directory underneath the public_html + directory: + + <dl> + <dd><code><Directory + /home/*/public_html/cgi-bin><br /> + Options ExecCGI<br /> + SetHandler cgi-script<br /> + </Directory></code></dd> + </dl> + </li> + </ol> + <p>If you are using suexec, the first technique will not work + because CGI scripts must be stored under the <code>public_html</code> + directory.</p> + + <hr /> + </li> + </ol> + + + </body> +</html> + + + + + + + + + + + + + + + + <h3>G. Authentication and Access Restrictions</h3> + + <ol> + <li> + <a id="dnsauth" name="dnsauth"><strong>Why isn't + restricting access by host or domain name working + correctly?</strong></a> + + <p>Two of the most common causes of this are:</p> + + <ol> + <li><strong>An error, inconsistency, or unexpected + mapping in the DNS registration</strong><br /> + This happens frequently: your configuration restricts + access to <samp>Host.FooBar.Com</samp>, but you can't get + in from that host. The usual reason for this is that + <samp>Host.FooBar.Com</samp> is actually an alias for + another name, and when Apache performs the + address-to-name lookup it's getting the <em>real</em> + name, not <samp>Host.FooBar.Com</samp>. You can verify + this by checking the reverse lookup yourself. The easiest + way to work around it is to specify the correct host name + in your configuration.</li> + + <li> + <strong>Inadequate checking and verification in your + configuration of Apache</strong><br /> + If you intend to perform access checking and + restriction based upon the client's host or domain + name, you really need to configure Apache to + double-check the origin information it's supplied. You + do this by adding the <samp>-DMAXIMUM_DNS</samp> clause + to the <samp>EXTRA_CFLAGS</samp> definition in your + <samp>Configuration</samp> file. For example: + + <dl> + <dd><code>EXTRA_CFLAGS=-DMAXIMUM_DNS</code></dd> + </dl> + + <p>This will cause Apache to be very paranoid about + making sure a particular host address is + <em>really</em> assigned to the name it claims to be. + Note that this <em>can</em> incur a significant + performance penalty, however, because of all the name + resolution requests being sent to a nameserver.</p> + </li> + </ol> + <hr /> + </li> + + <li> + <a id="user-authentication" + name="user-authentication"><strong>How do I set up Apache + to require a username and password to access certain + documents?</strong></a> + + <p>There are several ways to do this; some of the more + popular ones are to use the <a + href="../mod/mod_auth.html">mod_auth</a>, <a + href="../mod/mod_auth_db.html">mod_auth_db</a>, or <a + href="../mod/mod_auth_dbm.html">mod_auth_dbm</a> + modules.</p> + + <p>For an explanation on how to implement these + restrictions, see <a + href="http://www.apacheweek.com/"><cite>Apache + Week</cite></a>'s articles on <a + href="http://www.apacheweek.com/features/userauth"><cite>Using + User Authentication</cite></a> or <a + href="http://www.apacheweek.com/features/dbmauth"><cite>DBM + User Authentication</cite></a>, or see the <a + href="../howto/auth.html">authentication tutorial</a> in the + Apache documentation.</p> + <hr /> + </li> + + <li> + <a id="remote-auth-only" + name="remote-auth-only"><strong>How do I set up Apache to + allow access to certain documents only if a site is either + a local site <em>or</em> the user supplies a password and + username?</strong></a> + + <p>Use the <a href="../mod/core.html#satisfy">Satisfy</a> + directive, in particular the <code>Satisfy Any</code> + directive, to require that only one of the access + restrictions be met. For example, adding the following + configuration to a <samp>.htaccess</samp> or server + configuration file would restrict access to people who + either are accessing the site from a host under domain.com + or who can supply a valid username and password:</p> + + <dl> + <dd><code>Deny from all<br /> + Allow from .domain.com<br /> + AuthType Basic<br /> + AuthUserFile /usr/local/apache/conf/htpasswd.users<br /> + AuthName "special directory"<br /> + Require valid-user<br /> + Satisfy any</code></dd> + </dl> + + <p>See the <a href="#user-authentication">user + authentication</a> question and the <a + href="../mod/mod_access.html">mod_access</a> module for + details on how the above directives work.</p> + <hr /> + </li> + + <li> + <a id="authauthoritative" + name="authauthoritative"><strong>Why does my authentication + give me a server error?</strong></a> + + <p>Under normal circumstances, the Apache access control + modules will pass unrecognized user IDs on to the next + access control module in line. Only if the user ID is + recognized and the password is validated (or not) will it + give the usual success or "authentication failed" + messages.</p> + + <p>However, if the last access module in line 'declines' + the validation request (because it has never heard of the + user ID or because it is not configured), the + <samp>http_request</samp> handler will give one of the + following, confusing, errors:</p> + + <ul> + <li><samp>check access</samp></li> + + <li><samp>check user. No user file?</samp></li> + + <li><samp>check access. No groups file?</samp></li> + </ul> + + <p>This does <em>not</em> mean that you have to add an + '<samp>AuthUserFile /dev/null</samp>' line as some + magazines suggest!</p> + + <p>The solution is to ensure that at least the last module + is authoritative and <strong>CONFIGURED</strong>. By + default, <samp>mod_auth</samp> is authoritative and will + give an OK/Denied, but only if it is configured with the + proper <samp>AuthUserFile</samp>. Likewise, if a valid + group is required. (Remember that the modules are processed + in the reverse order from that in which they appear in your + compile-time <samp>Configuration</samp> file.)</p> + + <p>A typical situation for this error is when you are using + the <samp>mod_auth_dbm</samp>, <samp>mod_auth_msql</samp>, + <samp>mod_auth_mysql</samp>, <samp>mod_auth_anon</samp> or + <samp>mod_auth_cookie</samp> modules on their own. These + are by default <strong>not</strong> authoritative, and this + will pass the buck on to the (non-existent) next + authentication module when the user ID is not in their + respective database. Just add the appropriate + '<samp><em>XXX</em>Authoritative yes</samp>' line to the + configuration.</p> + + <p>In general it is a good idea (though not terribly + efficient) to have the file-based <samp>mod_auth</samp> a + module of last resort. This allows you to access the web + server with a few special passwords even if the databases + are down or corrupted. This does cost a file + open/seek/close for each request in a protected area.</p> + <hr /> + </li> + + <li> + <a id="auth-on-same-machine" + name="auth-on-same-machine"><strong>Do I have to keep the + (mSQL) authentication information on the same + machine?</strong></a> + + <p>Some organizations feel very strongly about keeping the + authentication information on a different machine than the + webserver. With the <samp>mod_auth_msql</samp>, + <samp>mod_auth_mysql</samp>, and other SQL modules + connecting to (R)DBMses this is quite possible. Just + configure an explicit host to contact.</p> + + <p>Be aware that with mSQL and Oracle, opening and closing + these database connections is very expensive and time + consuming. You might want to look at the code in the + <samp>auth_*</samp> modules and play with the compile time + flags to alleviate this somewhat, if your RDBMS licences + allow for it.</p> + <hr /> + </li> + + <li> + <a id="msql-slow" name="msql-slow"><strong>Why is my mSQL + authentication terribly slow?</strong></a> + + <p>You have probably configured the Host by specifying a + FQHN, and thus the <samp>libmsql</samp> will use a full + blown TCP/IP socket to talk to the database, rather than a + fast internal device. The <samp>libmsql</samp>, the mSQL + FAQ, and the <samp>mod_auth_msql</samp> documentation warn + you about this. If you have to use different hosts, check + out the <samp>mod_auth_msql</samp> code for some compile + time flags which might - or might not - suit you.</p> + <hr /> + </li> + + <li> + <a id="passwdauth" name="passwdauth"><strong>Can I use my + <samp>/etc/passwd</samp> file for Web page + authentication?</strong></a> + + <p>Yes, you can - but it's a <strong>very bad + idea</strong>. Here are some of the reasons:</p> + + <ul> + <li>The Web technology provides no governors on how often + or how rapidly password (authentication failure) retries + can be made. That means that someone can hammer away at + your system's <samp>root</samp> password using the Web, + using a dictionary or similar mass attack, just as fast + as the wire and your server can handle the requests. Most + operating systems these days include attack detection + (such as <em>n</em> failed passwords for the same account + within <em>m</em> seconds) and evasion (breaking the + connection, disabling the account under attack, disabling + <em>all</em> logins from that source, <em>et + cetera</em>), but the Web does not.</li> + + <li>An account under attack isn't notified (unless the + server is heavily modified); there's no "You have 19483 + login failures" message when the legitimate owner logs + in.</li> + + <li>Without an exhaustive and error-prone examination of + the server logs, you can't tell whether an account has + been compromised. Detecting that an attack has occurred, + or is in progress, is fairly obvious, though - + <em>if</em> you look at the logs.</li> + + <li>Web authentication passwords (at least for Basic + authentication) generally fly across the wire, and + through intermediate proxy systems, in what amounts to + plain text. "O'er the net we go/Caching all the way;/O + what fun it is to surf/Giving my password away!"</li> + + <li>Since HTTP is stateless, information about the + authentication is transmitted <em>each and every + time</em> a request is made to the server. Essentially, + the client caches it after the first successful access, + and transmits it without asking for all subsequent + requests to the same server.</li> + + <li>It's relatively trivial for someone on your system to + put up a page that will steal the cached password from a + client's cache without them knowing. Can you say + "password grabber"?</li> + </ul> + + <p>If you still want to do this in light of the above + disadvantages, the method is left as an exercise for the + reader. It'll void your Apache warranty, though, and you'll + lose all accumulated UNIX guru points.</p> + <hr /> + </li> + + <li> + <a id="prompted-twice" name="prompted-twice"><strong>Why + does Apache ask for my password twice before serving a + file?</strong></a> + + <p>If the hostname under which you are accessing the server + is different than the hostname specified in the <a + href="../mod/core.html#servername"><code>ServerName</code></a> + directive, then depending on the setting of the <a + href="../mod/core.html#usecanonicalname"><code>UseCanonicalName</code></a> + directive, Apache will redirect you to a new hostname when + constructing self-referential URLs. This happens, for + example, in the case where you request a directory without + including the trailing slash.</p> + + <p>When this happens, Apache will ask for authentication + once under the original hostname, perform the redirect, and + then ask again under the new hostname. For security + reasons, the browser must prompt again for the password + when the host name changes.</p> + + <p>To eliminate this problem you should</p> + + <ol> + <li>Always use the trailing slash when requesting + directories;</li> + + <li>Change the <code>ServerName</code> to match the name + you are using in the URL; and/or</li> + + <li>Set <code>UseCanonicalName off</code>.</li> + </ol> + <hr /> + </li> + + <li> + <a id="image-theft" name="image-theft"><strong>How can I prevent + people from "stealing" the images from my web site?</strong></a> + + <p>The goal here is to prevent people from inlining your images + directly from their web site, but accessing them only if they + appear inline in your pages.<p> + + <p>This can be accomplished with a combination of SetEnvIf and + the Deny and Allow directives. However, it is important to + understand that any access restriction based on the REFERER + header is intrinsically problematic due to the fact that + browsers can send an incorrect REFERER, either because they + want to circumvent your restriction or simply because they don't + send the right thing (or anything at all).</p> + + <p>The following configuration will produce the desired effect + if the browser passes correct REFERER headers.</p> + +<pre> +SetEnvIf REFERER "www\.mydomain\.com" linked_from_here +SetEnvIf REFERER "^$" linked_from_here + +<Directory /www/images> + Order deny,allow + Deny from all + Allow from env=linked_from_here +</Directory> +</pre> + +<p>Further examples can be found in the <a +href="../env.html#examples">Environment Variables</a> documentation.</p> + + <hr /> + </li> + + + </ol> + + + </body> +</html> + + + + + + + + + + + + + + + + <h3>H. URL Rewriting</h3> + + <ol> + <li> + <a id="rewrite-more-config" + name="rewrite-more-config"><strong>Where can I find + mod_rewrite rulesets which already solve particular + URL-related problems?</strong></a> + + <p>There is a collection of <a + href="http://www.engelschall.com/pw/apache/rewriteguide/">Practical + Solutions for URL-Manipulation</a> where you can find all + typical solutions the author of <a + href="../mod/mod_rewrite.html"><samp>mod_rewrite</samp></a> + currently knows of. If you have more interesting rulesets + which solve particular problems not currently covered in + this document, send it to <a + href="mailto:rse@apache.org">Ralf S. Engelschall</a> for + inclusion. The other webmasters will thank you for avoiding + the reinvention of the wheel.</p> + <hr /> + </li> + + <li> + <a id="rewrite-article" + name="rewrite-article"><strong>Where can I find any + published information about URL-manipulations and + mod_rewrite?</strong></a> + + <p>There is an article from <a + href="mailto:rse@apache.org">Ralf S. Engelschall</a> about + URL-manipulations based on <a + href="../mod/mod_rewrite.html"><samp>mod_rewrite</samp></a> + in the "iX Multiuser Multitasking Magazin" issue #12/96. + The german (original) version can be read online at <<a + href="http://www.heise.de/ix/artikel/9612149/">http://www.heise.de/ix/artikel/9612149/</a>>, + the English (translated) version can be found at <<a + href="http://www.heise.de/ix/artikel/E/9612149/">http://www.heise.de/ix/artikel/E/9612149/</a>>.</p> + <hr /> + </li> + + <li> + <a id="rewrite-complexity" + name="rewrite-complexity"><strong>Why is mod_rewrite so + difficult to learn and seems so complicated?</strong></a> + + <p>Hmmm... there are a lot of reasons. First, mod_rewrite + itself is a powerful module which can help you in really + <strong>all</strong> aspects of URL rewriting, so it can be + no trivial module per definition. To accomplish its hard + job it uses software leverage and makes use of a powerful + regular expression library by Henry Spencer which is an + integral part of Apache since its version 1.2. And regular + expressions itself can be difficult to newbies, while + providing the most flexible power to the advanced + hacker.</p> + + <p>On the other hand mod_rewrite has to work inside the + Apache API environment and needs to do some tricks to fit + there. For instance the Apache API as of 1.x really was not + designed for URL rewriting at the <tt>.htaccess</tt> level + of processing. Or the problem of multiple rewrites in + sequence, which is also not handled by the API per design. + To provide this features mod_rewrite has to do some special + (but API compliant!) handling which leads to difficult + processing inside the Apache kernel. While the user usually + doesn't see anything of this processing, it can be + difficult to find problems when some of your RewriteRules + seem not to work.</p> + <hr /> + </li> + + <li> + <a id="rewrite-dontwork" + name="rewrite-dontwork"><strong>What can I do if my + RewriteRules don't work as expected?</strong></a> + + <p>Use "<samp>RewriteLog somefile</samp>" and + "<samp>RewriteLogLevel 9</samp>" and have a precise look at + the steps the rewriting engine performs. This is really the + only one and best way to debug your rewriting + configuration.</p> + <hr /> + </li> + + <li> + <a id="rewrite-prefixdocroot" + name="rewrite-prefixdocroot"><strong>Why don't some of my + URLs get prefixed with DocumentRoot when using + mod_rewrite?</strong></a> + + <p>If the rule starts with <samp>/somedir/...</samp> make + sure that really no <samp>/somedir</samp> exists on the + filesystem if you don't want to lead the URL to match this + directory, <em>i.e.</em>, there must be no root directory + named <samp>somedir</samp> on the filesystem. Because if + there is such a directory, the URL will not get prefixed + with DocumentRoot. This behavior looks ugly, but is really + important for some other aspects of URL rewriting.</p> + <hr /> + </li> + + <li> + <a id="rewrite-nocase" name="rewrite-nocase"><strong>How + can I make all my URLs case-insensitive with + mod_rewrite?</strong></a> + + <p>You can't! The reasons are: first, that, case + translations for arbitrary length URLs cannot be done + <em>via</em> regex patterns and corresponding + substitutions. One needs a per-character pattern like the + sed/Perl <samp>tr|..|..|</samp> feature. Second, just + making URLs always upper or lower case does not solve the + whole problem of case-INSENSITIVE URLs, because URLs + actually have to be rewritten to the correct case-variant + for the file residing on the filesystem in order to allow + Apache to access the file. And the Unix filesystem is + always case-SENSITIVE.</p> + + <p>But there is a module named <code><a + href="../mod/mod_speling.html">mod_speling.c</a></code> in + the Apache distribution. Try this module to help correct + people who use mis-cased URLs.</p> + <hr /> + </li> + + <li> + <a id="rewrite-virthost" + name="rewrite-virthost"><strong>Why are RewriteRules in my + VirtualHost parts ignored?</strong></a> + + <p>Because you have to enable the engine for every virtual + host explicitly due to security concerns. Just add a + "RewriteEngine on" to your virtual host configuration + parts.</p> + <hr /> + </li> + + <li> + <a id="rewrite-envwhitespace" + name="rewrite-envwhitespace"><strong>How can I use strings + with whitespaces in RewriteRule's ENV flag?</strong></a> + + <p>There is only one ugly solution: You have to surround + the complete flag argument by quotation marks + (<samp>"[E=...]"</samp>). Notice: The argument to quote + here is not the argument to the E-flag, it is the argument + of the Apache config file parser, <em>i.e.</em>, the third + argument of the RewriteRule here. So you have to write + <samp>"[E=any text with whitespaces]"</samp>.</p> + <hr /> + </li> + </ol> + + + </body> +</html> + + + + + + + + + + + + + + + + <h3>I. Features</h3> + + <ol> + <li> + <a id="proxy" name="proxy"><strong>Does or will Apache act + as a Proxy server?</strong></a> + + <p>Apache version 1.1 and above comes with a <a + href="../mod/mod_proxy.html">proxy module</a>. If compiled + in, this will make Apache act as a caching-proxy + server.</p> + <hr /> + </li> + + <li> + <a id="multiviews" name="multiviews"><strong>What are + "multiviews"?</strong></a> + + <p>"Multiviews" is the general name given to the Apache + server's ability to provide language-specific document + variants in response to a request. This is documented quite + thoroughly in the <a href="../content-negotiation.html" + rel="Help">content negotiation</a> description page. In + addition, <cite>Apache Week</cite> carried an article on + this subject entitled "<a + href="http://www.apacheweek.com/features/negotiation" + rel="Help"><cite>Content Negotiation + Explained</cite></a>".</p> + <hr /> + </li> + + <li> + <a id="putsupport" name="putsupport"><strong>Why can't I + publish to my Apache server using PUT on Netscape Gold and + other programs?</strong></a> + + <p>Because you need to install and configure a script to + handle the uploaded files. This script is often called a + "PUT" handler. There are several available, but they may + have security problems. Using FTP uploads may be easier and + more secure, at least for now. For more information, see + the <cite>Apache Week</cite> article <a + href="http://www.apacheweek.com/features/put"><cite>Publishing + Pages with PUT</cite></a>.</p> + <hr /> + </li> + + <li> + <a id="SSL-i" name="SSL-i"><strong>Why doesn't Apache + include SSL?</strong></a> + + <p>SSL (Secure Socket Layer) data transport requires + encryption, and many governments have restrictions upon the + import, export, and use of encryption technology. If Apache + included SSL in the base package, its distribution would + involve all sorts of legal and bureaucratic issues, and it + would no longer be freely available. Also, some of the + technology required to talk to current clients using SSL is + patented by <a href="http://www.rsa.com/">RSA Data + Security</a>, who restricts its use without a license.</p> + + <p>Some SSL implementations of Apache are available, + however; see the "<a + href="http://httpd.apache.org/related_projects.html">related + projects</a>" page at the main Apache web site.</p> + + <p>You can find out more about this topic in the + <cite>Apache Week</cite> article about <a + href="http://www.apacheweek.com/features/ssl" + rel="Help"><cite>Apache and Secure + Transactions</cite></a>.</p> + <hr /> + </li> + + <li> + <a id="footer" name="footer"><strong>How can I attach a + footer to my documents without using SSI?</strong></a> + + <p>You can make arbitrary changes to static documents by + configuring an <a + href="../mod/mod_actions.html#action">Action</a> which + launches a CGI script. The CGI is then responsible for + setting a content-type and delivering the requested + document (the location of which is passed in the + <samp>PATH_TRANSLATED</samp> environment variable), along + with whatever footer is needed.</p> + + <p>Busy sites may not want to run a CGI script on every + request, and should consider using an Apache module to add + the footer. There are several third party modules available + through the <a href="http://modules.apache.org/">Apache + Module Registry</a> which will add footers to documents. + These include mod_trailer, PHP + (<samp>php3_auto_append_file</samp>), mod_layout, and + mod_perl (<samp>Apache::Sandwich</samp>).</p> + <hr /> + </li> + + <li> + <a id="search" name="search"><strong>Does Apache include a + search engine?</strong></a> + + <p>Apache does not include a search engine, but there are + many good commercial and free search engines which can be + used easily with Apache. Some of them are listed on the <a + href="http://www.searchtools.com/tools/tools.html">Web Site + Search Tools</a> page. Open source search engines that are + often used with Apache include <a + href="http://www.htdig.org/">ht://Dig</a> and <a + href="http://sunsite.berkeley.edu/SWISH-E/">SWISH-E</a>.</p> + <hr /> + </li> + + <li> + <a id="rotate" name="rotate"><strong>How can I rotate my + log files?</strong></a> + + <p>The simple answer: by piping the transfer log into an + appropriate log file rotation utility.</p> + + <p>The longer answer: In the src/support/ directory, you + will find a utility called <a + href="../programs/rotatelogs.html">rotatelogs</a> which can + be used like this:</p> +<pre> + TransferLog "|/path/to/rotatelogs /path/to/logs/access_log 86400" +</pre> + + <p>to enable daily rotation of the log files.<br /> + A more sophisticated solution of a logfile rotation + utility is available under the name <code>cronolog</code> + from Andrew Ford's site at <a + href="http://www.cronolog.org/">http://www.cronolog.org/</a>. + It can automatically create logfile subdirectories based on + time and date, and can have a constant symlink point to the + rotating logfiles. (As of version 1.6.1, cronolog is + available under the <a href="../LICENSE">Apache + License</a>). Use it like this:</p> +<pre> + CustomLog "|/path/to/cronolog --symlink=/usr/local/apache/logs/access_log /usr/local/apache/logs/%Y/%m/access_log" combined +</pre> + <hr /> + </li> + + <li> + <a id="conditional-logging" + name="conditional-logging"><strong>How do I keep certain + requests from appearing in my logs?</strong></a> + + <p>The maximum flexibility for removing unwanted + information from log files is obtained by post-processing + the logs, or using piped-logs to feed the logs through a + program which does whatever you want. However, Apache does + offer the ability to prevent requests from ever appearing + in the log files. You can do this by using the <a + href="../mod/mod_setenvif.html#setenvif"><code>SetEnvIf</code></a> + directive to set an environment variable for certain + requests and then using the conditional <a + href="../mod/mod_log_config.html#customlog-conditional"><code> + CustomLog</code></a> syntax to prevent logging when the + environment variable is set.</p> + <hr /> + </li> + + <li> + <a id="dbinteg" name="dbinteg"><b>Does Apache support any + sort of database integration?</b></a> + + <p>No. Apache is a Web (HTTP) server, not an application + server. The base package does not include any such + functionality. See the <a href="http://www.php.net/">PHP + project</a> and the <a + href="http://perl.apache.org/">mod_perl project</a> for + examples of modules that allow you to work with databases + from within the Apache environment.</p> + <hr /> + </li> + + <li> + <a id="asp" name="asp"><b>Can I use Active Server Pages + (ASP) with Apache?</b></a> + + <p>The base Apache Web server package does not include ASP + support. However, there are a couple of after-market + solutions that let you add this functionality; see the <a + href="http://httpd.apache.org/related_projects.html">related + projects</a> page to find out more.</p> + <hr /> + </li> + + <li> + <a id="java" name="java"><b>Does Apache come with Java + support?</b></a> + + <p>The base Apache Web server package does not include + support for Java, Java Server Pages, Enterprise Java Beans, + or Java servlets. Those features are available as add-ons + from the Apache/Java project site, <URL:<a + href="http://jakarta.apache.org">http://jakarta.apache.org/</a>>.</p> + <hr /> + </li> + </ol> + + + </body> +</html> + + + <hr /> + + <h3 align="CENTER">Apache HTTP Server Version 1.3</h3> + <a href="./"><img src="../images/index.gif" alt="Index" /></a> + <a href="../"><img src="../images/home.gif" alt="Home" /></a> + + </body> +</html> + diff --git a/usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.en b/usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.en new file mode 100644 index 00000000000..9478e661e9a --- /dev/null +++ b/usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.en @@ -0,0 +1,2103 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<!--%hypertext --> +<!-- mod_rewrite.html --> +<!-- Documentation for the mod_rewrite Apache module --> + +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta name="generator" content="HTML Tidy, see www.w3.org" /> + + <title>Apache module mod_rewrite</title> + </head> + <!-- Background white, links blue (unvisited), navy (visited), red (active) --> + + <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" + vlink="#000080" alink="#FF0000"> + <blockquote> + <!-- page indentation --> + <div align="CENTER"> + <img src="../images/sub.gif" alt="[APACHE DOCUMENTATION]" /> + + <h3>Apache HTTP Server Version 1.3</h3> + </div> + + <br /> + + + <h1 align="CENTER">Module mod_rewrite<br /> + URL Rewriting Engine</h1> + + <p>This module provides a rule-based rewriting engine to + rewrite requested URLs on the fly.</p> + + <p><a href="module-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="module-dict.html#SourceFile" + rel="Help"><strong>Source File:</strong></a> + mod_rewrite.c<br /> + <a href="module-dict.html#ModuleIdentifier" + rel="Help"><strong>Module Identifier:</strong></a> + rewrite_module<br /> + <a href="module-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Available in + Apache 1.2 and later.</p> + <hr noshade="noshade" size="1" /> + <br /> + + + <h2>Summary</h2> + + <blockquote> + <blockquote> + <blockquote> + <em>``The great thing about mod_rewrite is it gives you + all the configurability and flexibility of Sendmail. + The downside to mod_rewrite is that it gives you all + the configurability and flexibility of Sendmail.''</em> + + + <div align="RIGHT"> + -- Brian Behlendorf<br /> + Apache Group + </div> + </blockquote> + </blockquote> + </blockquote> + + <blockquote> + <blockquote> + <blockquote> + <em>`` Despite the tons of examples and docs, + mod_rewrite is voodoo. Damned cool voodoo, but still + voodoo. ''</em> + + <div align="RIGHT"> + -- Brian Moore<br /> + bem@news.cmc.net + </div> + </blockquote> + </blockquote> + </blockquote> + Welcome to mod_rewrite, the Swiss Army Knife of URL + manipulation! + + <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, + for instance server variables, environment variables, HTTP + headers, time stamps and even external database lookups in + various formats can be used to achieve a really granular URL + matching.</p> + + <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 even 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> + + <p>But all this functionality and flexibility has its + drawback: complexity. So don't expect to understand this + entire module in just one day.</p> + + <p>This module was invented and originally written in April + 1996<br /> + and gifted exclusively to the The Apache Group in July 1997 + by</p> + + <blockquote> + <a href="http://www.engelschall.com/"><code>Ralf S. + Engelschall</code></a><br /> + <a + href="mailto:rse@engelschall.com"><code>rse@engelschall.com</code></a><br /> + <a + href="http://www.engelschall.com/"><code>www.engelschall.com</code></a> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h2>Table Of Contents</h2> + + <p><strong>Internal Processing</strong></p> + + <ul> + <li><a href="#InternalAPI">API Phases</a></li> + + <li><a href="#InternalRuleset">Ruleset Processing</a></li> + + <li><a href="#InternalBackRefs">Regex Back-Reference + Availability</a></li> + </ul> + + <p><strong>Configuration Directives</strong></p> + + <ul> + <li><a href="#RewriteEngine">RewriteEngine</a></li> + + <li><a href="#RewriteOptions">RewriteOptions</a></li> + + <li><a href="#RewriteLog">RewriteLog</a></li> + + <li><a href="#RewriteLogLevel">RewriteLogLevel</a></li> + + <li><a href="#RewriteLock">RewriteLock</a></li> + + <li><a href="#RewriteMap">RewriteMap</a></li> + + <li><a href="#RewriteBase">RewriteBase</a></li> + + <li><a href="#RewriteCond">RewriteCond</a></li> + + <li><a href="#RewriteRule">RewriteRule</a></li> + </ul> + <strong>Miscellaneous</strong> + + <ul> + <li><a href="#EnvVar">Environment Variables</a></li> + + <li><a href="#Solutions">Practical Solutions</a></li> + </ul> + <hr noshade="noshade" size="1" /> + + <center> + <h1><a id="Internal" name="Internal">Internal + Processing</a></h1> + </center> + <hr noshade="noshade" size="1" /> + + <p>The internal processing of this module is very complex but + needs to be explained once even to the average user to avoid + common mistakes and to let you exploit its full + functionality.</p> + + <h2><a id="InternalAPI" name="InternalAPI">API + Phases</a></h2> + + <p>First you have to understand that when Apache processes a + HTTP request it does this in phases. A hook for each of these + phases is provided by the Apache API. Mod_rewrite uses two of + these hooks: the URL-to-filename translation hook which is + used after the HTTP request has been read but before any + authorization starts and the Fixup hook which is triggered + after the authorization phases and after the per-directory + config files (<code>.htaccess</code>) have been read, but + before the content handler is activated.</p> + + <p>So, after a request comes in and Apache has determined the + corresponding server (or virtual server) the rewriting engine + starts processing of all mod_rewrite directives from the + per-server configuration in the URL-to-filename phase. A few + steps later when the final data directories are found, the + per-directory configuration directives of mod_rewrite are + triggered in the Fixup phase. In both situations mod_rewrite + rewrites URLs either to new URLs or to filenames, although + there is no obvious distinction between them. This is a usage + of the API which was not intended to be this way when the API + was designed, but as of Apache 1.x this is the only way + mod_rewrite can operate. To make this point more clear + remember the following two points:</p> + + <ol> + <li>Although mod_rewrite rewrites URLs to URLs, URLs to + filenames and even filenames to filenames, the API + currently provides only a URL-to-filename hook. In Apache + 2.0 the two missing hooks will be added to make the + processing more clear. But this point has no drawbacks for + the user, it is just a fact which should be remembered: + Apache does more in the URL-to-filename hook than the API + intends for it.</li> + + <li> + Unbelievably mod_rewrite provides URL manipulations in + per-directory context, <em>i.e.</em>, within + <code>.htaccess</code> files, although these are reached + a very long time after the URLs have been translated to + filenames. It has to be this way because + <code>.htaccess</code> files live in the filesystem, so + processing has already reached this stage. In other + words: According to the API phases at this time it is too + late for any URL manipulations. To overcome this chicken + and egg problem mod_rewrite uses a trick: When you + manipulate a URL/filename in per-directory context + mod_rewrite first rewrites the filename back to its + corresponding URL (which is usually impossible, but see + the <code>RewriteBase</code> directive below for the + trick to achieve this) and then initiates a new internal + sub-request with the new URL. This restarts processing of + the API phases. + + <p>Again mod_rewrite tries hard to make this complicated + step totally transparent to the user, but you should + remember here: While URL manipulations in per-server + context are really fast and efficient, per-directory + rewrites are slow and inefficient due to this chicken and + egg problem. But on the other hand this is the only way + mod_rewrite can provide (locally restricted) URL + manipulations to the average user.</p> + </li> + </ol> + + <p>Don't forget these two points!</p> + + <h2><a id="InternalRuleset" name="InternalRuleset">Ruleset + Processing</a></h2> + Now when mod_rewrite is triggered in these two API phases, it + reads the configured rulesets from its configuration + structure (which itself was either created on startup for + per-server context or during the directory walk of the Apache + kernel for per-directory context). Then the URL rewriting + engine is started with the contained ruleset (one or more + rules together with their conditions). The operation of the + URL rewriting engine itself is exactly the same for both + configuration contexts. Only the final result processing is + different. + + <p>The order of rules in the ruleset is important because the + rewriting engine processes them in a special (and not very + obvious) order. The rule is this: The rewriting engine loops + through the ruleset rule by rule (<code>RewriteRule</code> + directives) and when a particular rule matches it optionally + loops through existing corresponding conditions + (<code>RewriteCond</code> directives). For historical reasons + the conditions are given first, and so the control flow is a + little bit long-winded. See Figure 1 for more details.</p> + + <div align="CENTER"> + <table cellspacing="0" cellpadding="2" border="0"> + <tr> + <td bgcolor="#CCCCCC"><img + src="../images/mod_rewrite_fig1.gif" width="428" + height="385" + alt="[Needs graphics capability to display]" /></td> + </tr> + + <tr> + <td align="CENTER"><strong>Figure 1:</strong> The + control flow through the rewriting ruleset</td> + </tr> + </table> + </div> + + <p>As you can see, first the URL is matched against the + <em>Pattern</em> of each rule. When it fails mod_rewrite + immediately stops processing this rule and continues with the + next rule. If the <em>Pattern</em> matches, mod_rewrite looks + for corresponding rule conditions. If none are present, it + just substitutes the URL with a new value which is + constructed from the string <em>Substitution</em> and goes on + with its rule-looping. But if conditions exist, it starts an + inner loop for processing them in the order that they are + listed. For conditions the logic is different: we don't match + a pattern against the current URL. Instead we first create a + string <em>TestString</em> by expanding variables, + back-references, map lookups, <em>etc.</em> and then we try + to match <em>CondPattern</em> against it. If the pattern + doesn't match, the complete set of conditions and the + corresponding rule fails. If the pattern matches, then the + next condition is processed until no more conditions are + available. If all conditions match, processing is continued + with the substitution of the URL with + <em>Substitution</em>.</p> + + <h2><a id="quoting" name="quoting">Quoting Special + Characters</a></h2> + + <p>As of Apache 1.3.20, special characters in + <i>TestString</i> and <i>Substitution</i> strings can be + escaped (that is, treated as normal characters without their + usual special meaning) by prefixing them with a slosh ('\') + character. In other words, you can include an actual + dollar-sign character in a <i>Substitution</i> string by + using '<code>\$</code>'; this keeps mod_rewrite from trying + to treat it as a backreference.</p> + + <h2><a id="InternalBackRefs" name="InternalBackRefs">Regex + Back-Reference Availability</a></h2> + One important thing here has to be remembered: Whenever you + use parentheses in <em>Pattern</em> or in one of the + <em>CondPattern</em>, back-references are internally created + which can be used with the strings <code>$N</code> and + <code>%N</code> (see below). These are available for creating + the strings <em>Substitution</em> and <em>TestString</em>. + Figure 2 shows to which locations the back-references are + transfered for expansion. + + <div align="CENTER"> + <table cellspacing="0" cellpadding="2" border="0"> + <tr> + <td bgcolor="#CCCCCC"><img + src="../images/mod_rewrite_fig2.gif" width="381" + height="179" + alt="[Needs graphics capability to display]" /></td> + </tr> + + <tr> + <td align="CENTER"><strong>Figure 2:</strong> The + back-reference flow through a rule</td> + </tr> + </table> + </div> + + <p>We know this was a crash course on mod_rewrite's internal + processing. But you will benefit from this knowledge when + reading the following documentation of the available + directives.</p> + <hr noshade="noshade" size="1" /> + + <center> + <h1><a id="Configuration" + name="Configuration">Configuration Directives</a></h1> + </center> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteEngine" + name="RewriteEngine">RewriteEngine</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteEngine + on|off<br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <code>RewriteEngine + off</code><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host, directory, .htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> FileInfo<br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache + 1.2<br /> + + + <p>The <code>RewriteEngine</code> directive enables or + disables the runtime rewriting engine. If it is set to + <code>off</code> this module does no runtime processing at + all. It does not even update the <code>SCRIPT_URx</code> + environment variables.</p> + + <p>Use this directive to disable the module instead of + commenting out all the <code>RewriteRule</code> + directives!</p> + + <p>Note that, by default, rewrite configurations are not + inherited. This means that you need to have a + <code>RewriteEngine on</code> directive for each virtual host + in which you wish to use it.</p> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteOptions" + name="RewriteOptions">RewriteOptions</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteOptions + <em>Option</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <code>RewriteOptions + MaxRedirects=10</code><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host, directory, .htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> FileInfo<br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache + 1.2; <code>MaxRedirects</code> is available in Apache 1.3.28 and + later<br /> + + + <p>The <code>RewriteOptions</code> directive sets some + special options for the current per-server or per-directory + configuration. The <em>Option</em> strings can be one of the + following:</p> + + <dl> + <dt><code>inherit</code></dt> + <dd>This forces the current configuration to inherit the + configuration of the parent. In per-virtual-server context + this means that the maps, conditions and rules of the main + server are inherited. In per-directory context this means + that conditions and rules of the parent directory's + <code>.htaccess</code> configuration are inherited.</dd> + + <dt><code>MaxRedirects=<var>number</var></code></dt> + <dd>In order to prevent endless loops of internal redirects + issued by per-directory <code>RewriteRule</code>s, + <code>mod_rewrite</code> aborts the request after reaching a + maximum number of such redirects and responds with an 500 Internal + Server Error. If you really need more internal redirects than 10 + per request, you may increase the default to the desired value.</dd> + </dl> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteLog" name="RewriteLog">RewriteLog</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteLog + <em>file-path</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <em>None</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> <em>Not + applicable</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache + 1.2<br /> + + + <p>The <code>RewriteLog</code> directive sets the name of the + file to which the server logs any rewriting actions it + performs. If the name does not begin with a slash + ('<code>/</code>') then it is assumed to be relative to the + <em>Server Root</em>. The directive should occur only once + per server config.</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Note</strong>: To disable the logging of + rewriting actions it is not recommended to set + <em>file-path</em> to <code>/dev/null</code>, because + although the rewriting engine does not then output to a + logfile it still creates the logfile output internally. + <strong>This will slow down the server with no advantage + to the administrator!</strong> To disable logging either + remove or comment out the <code>RewriteLog</code> + directive or use <code>RewriteLogLevel 0</code>!</td> + </tr> + </table> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Security</strong>: See the <a + href="../misc/security_tips.html">Apache Security + Tips</a> document for details on why your security could + be compromised if the directory where logfiles are stored + is writable by anyone other than the user that starts the + server.</td> + </tr> + </table> + + <p><strong>Example:</strong></p> + + <blockquote> +<pre> +RewriteLog "/usr/local/var/apache/logs/rewrite.log" +</pre> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteLogLevel" + name="RewriteLogLevel">RewriteLogLevel</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteLogLevel + <em>Level</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> + <code>RewriteLogLevel 0</code><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> <em>Not + applicable</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache + 1.2<br /> + + + <p>The <code>RewriteLogLevel</code> directive sets the + verbosity level of the rewriting logfile. The default level 0 + means no logging, while 9 or more means that practically all + actions are logged.</p> + + <p>To disable the logging of rewriting actions simply set + <em>Level</em> to 0. This disables all rewrite action + logs.</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Notice:</strong> Using a high value for + <em>Level</em> will slow down your Apache server + dramatically! Use the rewriting logfile at a + <em>Level</em> greater than 2 only for debugging!</td> + </tr> + </table> + + <p><strong>Example:</strong></p> + + <blockquote> +<pre> +RewriteLogLevel 3 +</pre> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteLock" + name="RewriteLock">RewriteLock</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteLock + <em>file-path</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <em>None</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> <em>Not + applicable</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache + 1.3<br /> + + + <p>This directive sets the filename for a synchronization + lockfile which mod_rewrite needs to communicate with + <samp>RewriteMap</samp> <em>programs</em>. Set this lockfile + to a local path (not on a NFS-mounted device) when you want + to use a rewriting map-program. It is not required for other + types of rewriting maps.</p> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteMap" name="RewriteMap">RewriteMap</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteMap + <em>MapName</em> <em>MapType</em>:<em>MapSource</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> not used per + default<br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> <em>Not + applicable</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache 1.2 + (partially), Apache 1.3<br /> + + + <p>The <code>RewriteMap</code> directive defines a + <em>Rewriting Map</em> which can be used inside rule + substitution strings by the mapping-functions to + insert/substitute fields through a key lookup. The source of + this lookup can be of various types.</p> + + <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is + the name of the map and will be used to specify a + mapping-function for the substitution strings of a rewriting + rule via one of the following constructs:</p> + + <blockquote> + <strong><code>${</code> <em>MapName</em> <code>:</code> + <em>LookupKey</em> <code>}</code><br /> + <code>${</code> <em>MapName</em> <code>:</code> + <em>LookupKey</em> <code>|</code> <em>DefaultValue</em> + <code>}</code></strong> + </blockquote> + When such a construct occurs the map <em>MapName</em> is + consulted and the key <em>LookupKey</em> is looked-up. If the + key is found, the map-function construct is substituted by + <em>SubstValue</em>. If the key is not found then it is + substituted by <em>DefaultValue</em> or by the empty string + if no <em>DefaultValue</em> was specified. + + <p>The following combinations for <em>MapType</em> and + <em>MapSource</em> can be used:</p> + + <ul> + <li> + <strong>Standard Plain Text</strong><br /> + MapType: <code>txt</code>, MapSource: Unix filesystem + path to valid regular file + + <p>This is the standard rewriting map feature where the + <em>MapSource</em> is a plain ASCII file containing + either blank lines, comment lines (starting with a '#' + character) or pairs like the following - one per + line.</p> + + <blockquote> + <strong><em>MatchingKey</em> + <em>SubstValue</em></strong> + </blockquote> + + <p>Example:</p> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +## +## map.txt -- rewriting map +## + +Ralf.S.Engelschall rse # Bastard Operator From Hell +Mr.Joe.Average joe # Mr. Average +</pre> + </td> + </tr> + </table> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +RewriteMap real-to-user txt:/path/to/file/map.txt +</pre> + </td> + </tr> + </table> + </li> + + <li> + <strong>Randomized Plain Text</strong><br /> + MapType: <code>rnd</code>, MapSource: Unix filesystem + path to valid regular file + + <p>This is identical to the Standard Plain Text variant + above but with a special post-processing feature: After + looking up a value it is parsed according to contained + ``<code>|</code>'' characters which have the meaning of + ``or''. In other words they indicate a set of + alternatives from which the actual returned value is + chosen randomly. Although this sounds crazy and useless, + it was actually designed for load balancing in a reverse + proxy situation where the looked up values are server + names. Example:</p> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +## +## map.txt -- rewriting map +## + +static www1|www2|www3|www4 +dynamic www5|www6 +</pre> + </td> + </tr> + </table> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +RewriteMap servers rnd:/path/to/file/map.txt +</pre> + </td> + </tr> + </table> + </li> + + <li> + <strong>Hash File</strong><br /> + MapType: <code>dbm</code>, MapSource: Unix filesystem + path to valid regular file + + <p>Here the source is a binary NDBM format file + containing the same contents as a <em>Plain Text</em> + format file, but in a special representation which is + optimized for really fast lookups. You can create such a + file with any NDBM tool or with the following Perl + script:</p> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +#!/path/to/bin/perl +## +## txt2dbm -- convert txt map to dbm format +## + +use NDBM_File; +use Fcntl; + +($txtmap, $dbmmap) = @ARGV; + +open(TXT, "<$txtmap") or die "Couldn't open $txtmap!\n"; +tie (%DB, 'NDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644) or die "Couldn't create $dbmmap!\n"; + +while (<TXT>) { + next if (/^\s*#/ or /^\s*$/); + $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/); +} + +untie %DB; +close(TXT); +</pre> + </td> + </tr> + </table> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +$ txt2dbm map.txt map.db +</pre> + </td> + </tr> + </table> + </li> + + <li> + <strong>Internal Function</strong><br /> + MapType: <code>int</code>, MapSource: Internal Apache + function + + <p>Here the source is an internal Apache function. + Currently you cannot create your own, but the following + functions already exists:</p> + + <ul> + <li><strong>toupper</strong>:<br /> + Converts the looked up key to all upper case.</li> + + <li><strong>tolower</strong>:<br /> + Converts the looked up key to all lower case.</li> + + <li><strong>escape</strong>:<br /> + Translates special characters in the looked up key to + hex-encodings.</li> + + <li><strong>unescape</strong>:<br /> + Translates hex-encodings in the looked up key back to + special characters.</li> + </ul> + </li> + + <li> + <strong>External Rewriting Program</strong><br /> + MapType: <code>prg</code>, MapSource: Unix filesystem + path to valid regular file + + <p>Here the source is a program, not a map file. To + create it you can use the language of your choice, but + the result has to be a executable (<em>i.e.</em>, either + object-code or a script with the magic cookie trick + '<code>#!/path/to/interpreter</code>' as the first + line).</p> + + <p>This program is started once at startup of the Apache + servers and then communicates with the rewriting engine + over its <code>stdin</code> and <code>stdout</code> + file-handles. For each map-function lookup it will + receive the key to lookup as a newline-terminated string + on <code>stdin</code>. It then has to give back the + looked-up value as a newline-terminated string on + <code>stdout</code> or the four-character string + ``<code>NULL</code>'' if it fails (<em>i.e.</em>, there + is no corresponding value for the given key). A trivial + program which will implement a 1:1 map (<em>i.e.</em>, + key == value) could be:</p> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +#!/usr/bin/perl +$| = 1; +while (<STDIN>) { + # ...put here any transformations or lookups... + print $_; +} +</pre> + </td> + </tr> + </table> + + <p>But be very careful:<br /> + </p> + + <ol> + <li>``<em>Keep it simple, stupid</em>'' (KISS), because + if this program hangs it will hang the Apache server + when the rule occurs.</li> + + <li>Avoid one common mistake: never do buffered I/O on + <code>stdout</code>! This will cause a deadloop! Hence + the ``<code>$|=1</code>'' in the above example...</li> + + <li>Use the <samp>RewriteLock</samp> directive to + define a lockfile mod_rewrite can use to synchronize + the communication to the program. By default no such + synchronization takes place.</li> + </ol> + </li> + </ul> + The <code>RewriteMap</code> directive can occur more than + once. For each mapping-function use one + <code>RewriteMap</code> directive to declare its rewriting + mapfile. While you cannot <strong>declare</strong> a map in + per-directory context it is of course possible to + <strong>use</strong> this map in per-directory context. + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Note:</strong> For plain text and DBM format + files the looked-up keys are cached in-core until the + <code>mtime</code> of the mapfile changes or the server + does a restart. This way you can have map-functions in + rules which are used for <strong>every</strong> request. + This is no problem, because the external lookup only + happens once!</td> + </tr> + </table> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteBase" + name="RewriteBase">RewriteBase</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteBase + <em>URL-path</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <em>default is the + physical directory path</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> directory, + .htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> + <em>FileInfo</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache + 1.2<br /> + + + <p>The <code>RewriteBase</code> directive explicitly sets the + base URL for per-directory rewrites. As you will see below, + <code>RewriteRule</code> can be used in per-directory config + files (<code>.htaccess</code>). There it will act locally, + <em>i.e.</em>, the local directory prefix is stripped at this + stage of processing and your rewriting rules act only on the + remainder. At the end it is automatically added back to the + path.</p> + + <p>When a substitution occurs for a new URL, this module has + to re-inject the URL into the server processing. To be able + to do this it needs to know what the corresponding URL-prefix + or URL-base is. By default this prefix is the corresponding + filepath itself. <strong>But at most websites URLs are NOT + directly related to physical filename paths, so this + assumption will usually be wrong!</strong> There you have to + use the <code>RewriteBase</code> directive to specify the + correct URL-prefix.</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Notice:</strong> If your webserver's URLs are + <strong>not</strong> directly related to physical file + paths, you have to use <code>RewriteBase</code> in every + <code>.htaccess</code> files where you want to use + <code>RewriteRule</code> directives.</td> + </tr> + </table> + + <p><strong>Example:</strong></p> + + <blockquote> + Assume the following per-directory config file: + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +# +# /abc/def/.htaccess -- per-dir config file for directory /abc/def +# Remember: /abc/def is the physical path of /xyz, <em>i.e.</em>, the server +# has a 'Alias /xyz /abc/def' directive <em>e.g.</em> +# + +RewriteEngine On + +# let the server know that we were reached via /xyz and not +# via the physical path prefix /abc/def +RewriteBase /xyz + +# now the rewriting rules +RewriteRule ^oldstuff\.html$ newstuff.html +</pre> + </td> + </tr> + </table> + + <p>In the above example, a request to + <code>/xyz/oldstuff.html</code> gets correctly rewritten to + the physical file <code>/abc/def/newstuff.html</code>.</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td> + <font size="-1"><strong>Note - For Apache + hackers:</strong><br /> + The following list gives detailed information about + the internal processing steps:</font> +<pre> +<font size="-1">Request: + /xyz/oldstuff.html + +Internal Processing: + /xyz/oldstuff.html -> /abc/def/oldstuff.html (per-server Alias) + /abc/def/oldstuff.html -> /abc/def/newstuff.html (per-dir RewriteRule) + /abc/def/newstuff.html -> /xyz/newstuff.html (per-dir RewriteBase) + /xyz/newstuff.html -> /abc/def/newstuff.html (per-server Alias) + +Result: + /abc/def/newstuff.html +</font> +</pre> + <font size="-1">This seems very complicated but is + the correct Apache internal processing, because the + per-directory rewriting comes too late in the + process. So, when it occurs the (rewritten) request + has to be re-injected into the Apache kernel! BUT: + While this seems like a serious overhead, it really + isn't, because this re-injection happens fully + internally to the Apache server and the same + procedure is used by many other operations inside + Apache. So, you can be sure the design and + implementation is correct.</font> + </td> + </tr> + </table> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteCond" + name="RewriteCond">RewriteCond</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteCond + <em>TestString</em> <em>CondPattern</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <em>None</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host, directory, .htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> + <em>FileInfo</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache 1.2 + (partially), Apache 1.3<br /> + + + <p>The <code>RewriteCond</code> directive defines a rule + condition. Precede a <code>RewriteRule</code> directive with + one or more <code>RewriteCond</code> directives. The + following rewriting rule is only used if its pattern matches + the current state of the URI <strong>and</strong> if these + additional conditions apply too.</p> + + <p><em>TestString</em> is a string which can contains the + following expanded constructs in addition to plain text:</p> + + <ul> + <li> + <strong>RewriteRule backreferences</strong>: These are + backreferences of the form + + <blockquote> + <strong><code>$N</code></strong> + </blockquote> + (0 <= N <= 9) which provide access to the grouped + parts (parenthesis!) of the pattern from the + corresponding <code>RewriteRule</code> directive (the one + following the current bunch of <code>RewriteCond</code> + directives). + </li> + + <li> + <strong>RewriteCond backreferences</strong>: These are + backreferences of the form + + <blockquote> + <strong><code>%N</code></strong> + </blockquote> + (1 <= N <= 9) which provide access to the grouped + parts (parentheses!) of the pattern from the last matched + <code>RewriteCond</code> directive in the current bunch + of conditions. + </li> + + <li> + <strong>RewriteMap expansions</strong>: These are + expansions of the form + + <blockquote> + <strong><code>${mapname:key|default}</code></strong> + </blockquote> + See <a href="#mapfunc">the documentation for + RewriteMap</a> for more details. + </li> + + <li> + <strong>Server-Variables</strong>: These are variables of + the form + + <blockquote> + <strong><code>%{</code> <em>NAME_OF_VARIABLE</em> + <code>}</code></strong> + </blockquote> + where <em>NAME_OF_VARIABLE</em> can be a string taken + from the following list: + + <table bgcolor="#F0F0F0" cellspacing="0" cellpadding="5"> + <tr> + <td valign="TOP"> + <strong>HTTP headers:</strong> + + <p><font size="-1">HTTP_USER_AGENT<br /> + HTTP_REFERER<br /> + HTTP_COOKIE<br /> + HTTP_FORWARDED<br /> + HTTP_HOST<br /> + HTTP_PROXY_CONNECTION<br /> + HTTP_ACCEPT<br /> + </font></p> + </td> + + <td valign="TOP"> + <strong>connection & request:</strong> + + <p><font size="-1">REMOTE_ADDR<br /> + REMOTE_HOST<br /> + REMOTE_USER<br /> + REMOTE_IDENT<br /> + REQUEST_METHOD<br /> + SCRIPT_FILENAME<br /> + PATH_INFO<br /> + QUERY_STRING<br /> + AUTH_TYPE<br /> + </font></p> + </td> + </tr> + + <tr> + <td valign="TOP"> + <strong>server internals:</strong> + + <p><font size="-1">DOCUMENT_ROOT<br /> + SERVER_ADMIN<br /> + SERVER_NAME<br /> + SERVER_ADDR<br /> + SERVER_PORT<br /> + SERVER_PROTOCOL<br /> + SERVER_SOFTWARE<br /> + </font></p> + </td> + + <td valign="TOP"> + <strong>system stuff:</strong> + + <p><font size="-1">TIME_YEAR<br /> + TIME_MON<br /> + TIME_DAY<br /> + TIME_HOUR<br /> + TIME_MIN<br /> + TIME_SEC<br /> + TIME_WDAY<br /> + TIME<br /> + </font></p> + </td> + + <td valign="TOP"> + <strong>specials:</strong> + + <p><font size="-1">API_VERSION<br /> + THE_REQUEST<br /> + REQUEST_URI<br /> + REQUEST_FILENAME<br /> + IS_SUBREQ<br /> + </font></p> + </td> + </tr> + </table> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td> + <p><strong>Notice:</strong> These variables all + correspond to the similarly named HTTP + MIME-headers, C variables of the Apache server or + <code>struct tm</code> fields of the Unix system. + Most are documented elsewhere in the Manual or in + the CGI specification. Those that are special to + mod_rewrite include:</p> + + <dl> + <dt><code>IS_SUBREQ</code></dt> + + <dd>Will contain the text "true" if the request + currently being processed is a sub-request, + "false" otherwise. Sub-requests may be generated + by modules that need to resolve additional files + or URIs in order to complete their tasks.</dd> + + <dt><code>API_VERSION</code></dt> + + <dd>This is the version of the Apache module API + (the internal interface between server and + module) in the current httpd build, as defined in + include/ap_mmn.h. The module API version + corresponds to the version of Apache in use (in + the release version of Apache 1.3.14, for + instance, it is 19990320:10), but is mainly of + interest to module authors.</dd> + + <dt><code>THE_REQUEST</code></dt> + + <dd>The full HTTP request line sent by the + browser to the server (e.g., "<code>GET + /index.html HTTP/1.1</code>"). This does not + include any additional headers sent by the + browser.</dd> + + <dt><code>REQUEST_URI</code></dt> + + <dd>The resource requested in the HTTP request + line. (In the example above, this would be + "/index.html".)</dd> + + <dt><code>REQUEST_FILENAME</code></dt> + + <dd>The full local filesystem path to the file or + script matching the request.</dd> + </dl> + </td> + </tr> + </table> + </li> + </ul> + + <p>Special Notes:</p> + + <ol> + <li>The variables SCRIPT_FILENAME and REQUEST_FILENAME + contain the same value, <em>i.e.</em>, the value of the + <code>filename</code> field of the internal + <code>request_rec</code> structure of the Apache server. + The first name is just the commonly known CGI variable name + while the second is the consistent counterpart to + REQUEST_URI (which contains the value of the + <code>uri</code> field of <code>request_rec</code>).</li> + + <li>There is the special format: + <code>%{ENV:variable}</code> where <em>variable</em> can be + any environment variable. This is looked-up via internal + Apache structures and (if not found there) via + <code>getenv()</code> from the Apache server process.</li> + + <li>There is the special format: + <code>%{HTTP:header}</code> where <em>header</em> can be + any HTTP MIME-header name. This is looked-up from the HTTP + request. Example: <code>%{HTTP:Proxy-Connection}</code> is + the value of the HTTP header + ``<code>Proxy-Connection:</code>''.</li> + + <li>There is the special format + <code>%{LA-U:variable}</code> for look-aheads which perform + an internal (URL-based) sub-request to determine the final + value of <em>variable</em>. Use this when you want to use a + variable for rewriting which is actually set later in an + API phase and thus is not available at the current stage. + For instance when you want to rewrite according to the + <code>REMOTE_USER</code> variable from within the + per-server context (<code>httpd.conf</code> file) you have + to use <code>%{LA-U:REMOTE_USER}</code> because this + variable is set by the authorization phases which come + <em>after</em> the URL translation phase where mod_rewrite + operates. On the other hand, because mod_rewrite implements + its per-directory context (<code>.htaccess</code> file) via + the Fixup phase of the API and because the authorization + phases come <em>before</em> this phase, you just can use + <code>%{REMOTE_USER}</code> there.</li> + + <li>There is the special format: + <code>%{LA-F:variable}</code> which performs an internal + (filename-based) sub-request to determine the final value + of <em>variable</em>. Most of the time this is the same as + LA-U above.</li> + </ol> + + <p><em>CondPattern</em> is the condition pattern, + <em>i.e.</em>, a regular expression which is applied to the + current instance of the <em>TestString</em>, <em>i.e.</em>, + <em>TestString</em> is evaluated and then matched against + <em>CondPattern</em>.</p> + + <p><strong>Remember:</strong> <em>CondPattern</em> is a + standard <em>Extended Regular Expression</em> with some + additions:</p> + + <ol> + <li>You can prefix the pattern string with a + '<code>!</code>' character (exclamation mark) to specify a + <strong>non</strong>-matching pattern.</li> + + <li> + There are some special variants of <em>CondPatterns</em>. + Instead of real regular expression strings you can also + use one of the following: + + <ul> + <li>'<strong><CondPattern</strong>' (is lexically + lower)<br /> + Treats the <em>CondPattern</em> as a plain string and + compares it lexically to <em>TestString</em>. True if + <em>TestString</em> is lexically lower than + <em>CondPattern</em>.</li> + + <li>'<strong>>CondPattern</strong>' (is lexically + greater)<br /> + Treats the <em>CondPattern</em> as a plain string and + compares it lexically to <em>TestString</em>. True if + <em>TestString</em> is lexically greater than + <em>CondPattern</em>.</li> + + <li>'<strong>=CondPattern</strong>' (is lexically + equal)<br /> + Treats the <em>CondPattern</em> as a plain string and + compares it lexically to <em>TestString</em>. True if + <em>TestString</em> is lexically equal to + <em>CondPattern</em>, i.e the two strings are exactly + equal (character by character). If <em>CondPattern</em> + is just <samp>""</samp> (two quotation marks) this + compares <em>TestString</em> to the empty string.</li> + + <li>'<strong>-d</strong>' (is + <strong>d</strong>irectory)<br /> + Treats the <em>TestString</em> as a pathname and tests + if it exists and is a directory.</li> + + <li>'<strong>-f</strong>' (is regular + <strong>f</strong>ile)<br /> + Treats the <em>TestString</em> as a pathname and tests + if it exists and is a regular file.</li> + + <li>'<strong>-s</strong>' (is regular file with + <strong>s</strong>ize)<br /> + Treats the <em>TestString</em> as a pathname and tests + if it exists and is a regular file with size greater + than zero.</li> + + <li>'<strong>-l</strong>' (is symbolic + <strong>l</strong>ink)<br /> + Treats the <em>TestString</em> as a pathname and tests + if it exists and is a symbolic link.</li> + + <li>'<strong>-F</strong>' (is existing file via + subrequest)<br /> + Checks if <em>TestString</em> is a valid file and + accessible via all the server's currently-configured + access controls for that path. This uses an internal + subrequest to determine the check, so use it with care + because it decreases your servers performance!</li> + + <li>'<strong>-U</strong>' (is existing URL via + subrequest)<br /> + Checks if <em>TestString</em> is a valid URL and + accessible via all the server's currently-configured + access controls for that path. This uses an internal + subrequest to determine the check, so use it with care + because it decreases your server's performance!</li> + </ul> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Notice:</strong> All of these tests can + also be prefixed by an exclamation mark ('!') to + negate their meaning.</td> + </tr> + </table> + </li> + </ol> + + <p>Additionally you can set special flags for + <em>CondPattern</em> by appending</p> + + <blockquote> + <strong><code>[</code><em>flags</em><code>]</code></strong> + </blockquote> + as the third argument to the <code>RewriteCond</code> + directive. <em>Flags</em> is a comma-separated list of the + following flags: + + <ul> + <li>'<strong><code>nocase|NC</code></strong>' + (<strong>n</strong>o <strong>c</strong>ase)<br /> + This makes the test case-insensitive, <em>i.e.</em>, there + is no difference between 'A-Z' and 'a-z' both in the + expanded <em>TestString</em> and the <em>CondPattern</em>. + This flag is effective only for comparisons between + <em>TestString</em> and <em>CondPattern</em>. It has no + effect on filesystem and subrequest checks.</li> + + <li> + '<strong><code>ornext|OR</code></strong>' + (<strong>or</strong> next condition)<br /> + Use this to combine rule conditions with a local OR + instead of the implicit AND. Typical example: + + <blockquote> +<pre> +RewriteCond %{REMOTE_HOST} ^host1.* [OR] +RewriteCond %{REMOTE_HOST} ^host2.* [OR] +RewriteCond %{REMOTE_HOST} ^host3.* +RewriteRule ...some special stuff for any of these hosts... +</pre> + </blockquote> + Without this flag you would have to write the cond/rule + three times. + </li> + </ul> + + <p><strong>Example:</strong></p> + + <blockquote> + To rewrite the Homepage of a site according to the + ``<code>User-Agent:</code>'' header of the request, you can + use the following: + + <blockquote> +<pre> +RewriteCond %{HTTP_USER_AGENT} ^Mozilla.* +RewriteRule ^/$ /homepage.max.html [L] + +RewriteCond %{HTTP_USER_AGENT} ^Lynx.* +RewriteRule ^/$ /homepage.min.html [L] + +RewriteRule ^/$ /homepage.std.html [L] +</pre> + </blockquote> + Interpretation: If you use Netscape Navigator as your + browser (which identifies itself as 'Mozilla'), then you + get the max homepage, which includes Frames, <em>etc.</em> + If you use the Lynx browser (which is Terminal-based), then + you get the min homepage, which contains no images, no + tables, <em>etc.</em> If you use any other browser you get + the standard homepage. + </blockquote> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteRule" + name="RewriteRule">RewriteRule</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteRule + <em>Pattern</em> <em>Substitution</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <em>None</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host, directory, .htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> + <em>FileInfo</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache 1.2 + (partially), Apache 1.3<br /> + + + <p>The <code>RewriteRule</code> directive is the real + rewriting workhorse. The directive can occur more than once. + Each directive then defines one single rewriting rule. The + <strong>definition order</strong> of these rules is + <strong>important</strong>, because this order is used when + applying the rules at run-time.</p> + + <p><a id="patterns" name="patterns"><em>Pattern</em></a> can + be (for Apache 1.1.x a System V8 and for Apache 1.2.x and + later a POSIX) <a id="regexp" name="regexp">regular + expression</a> which gets applied to the current URL. Here + ``current'' means the value of the URL when this rule gets + applied. This may not be the originally requested URL, + because any number of rules may already + have matched and made alterations to it.</p> + + <p>Some hints about the syntax of regular expressions:</p> + + <table bgcolor="#F0F0F0" cellspacing="0" cellpadding="5"> + <tr> + <td valign="TOP"> +<pre> +<strong>Text:</strong> + <strong><code>.</code></strong> Any single character + <strong><code>[</code></strong>chars<strong><code>]</code></strong> Character class: One of chars + <strong><code>[^</code></strong>chars<strong><code>]</code></strong> Character class: None of chars + text1<strong><code>|</code></strong>text2 Alternative: text1 or text2 + +<strong>Quantifiers:</strong> + <strong><code>?</code></strong> 0 or 1 of the preceding text + <strong><code>*</code></strong> 0 or N of the preceding text (N > 0) + <strong><code>+</code></strong> 1 or N of the preceding text (N > 1) + +<strong>Grouping:</strong> + <strong><code>(</code></strong>text<strong><code>)</code></strong> Grouping of text + (either to set the borders of an alternative or + for making backreferences where the <strong>N</strong>th group can + be used on the RHS of a RewriteRule with <code>$</code><strong>N</strong>) + +<strong>Anchors:</strong> + <strong><code>^</code></strong> Start of line anchor + <strong><code>$</code></strong> End of line anchor + +<strong>Escaping:</strong> + <strong><code>\</code></strong>char escape that particular char + (for instance to specify the chars "<code>.[]()</code>" <em>etc.</em>) +</pre> + </td> + </tr> + </table> + + <p>For more information about regular expressions either have + a look at your local regex(3) manpage or its + <code>src/regex/regex.3</code> copy in the Apache 1.3 + distribution. If you are interested in more detailed + information about regular expressions and their variants + (POSIX regex, Perl regex, <em>etc.</em>) have a look at the + following dedicated book on this topic:</p> + + <blockquote> + <em>Mastering Regular Expressions</em><br /> + Jeffrey E.F. Friedl<br /> + Nutshell Handbook Series<br /> + O'Reilly & Associates, Inc. 1997<br /> + ISBN 1-56592-257-3<br /> + </blockquote> + + <p>Additionally in mod_rewrite the NOT character + ('<code>!</code>') is a possible pattern prefix. This gives + you the ability to negate a pattern; to say, for instance: + ``<em>if the current URL does <strong>NOT</strong> match this + pattern</em>''. This can be used for exceptional cases, where + it is easier to match the negative pattern, or as a last + default rule.</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Notice:</strong> When using the NOT character + to negate a pattern you cannot have grouped wildcard + parts in the pattern. This is impossible because when the + pattern does NOT match, there are no contents for the + groups. In consequence, if negated patterns are used, you + cannot use <code>$N</code> in the substitution + string!</td> + </tr> + </table> + + <p><a id="rhs" name="rhs"><em>Substitution</em></a> of a + rewriting rule is the string which is substituted for (or + replaces) the original URL for which <em>Pattern</em> + matched. Beside plain text you can use</p> + + <ol> + <li>back-references <code>$N</code> to the RewriteRule + pattern</li> + + <li>back-references <code>%N</code> to the last matched + RewriteCond pattern</li> + + <li>server-variables as in rule condition test-strings + (<code>%{VARNAME}</code>)</li> + + <li><a href="#mapfunc">mapping-function</a> calls + (<code>${mapname:key|default}</code>)</li> + </ol> + Back-references are <code>$</code><strong>N</strong> + (<strong>N</strong>=0..9) identifiers which will be replaced + by the contents of the <strong>N</strong>th group of the + matched <em>Pattern</em>. The server-variables are the same + as for the <em>TestString</em> of a <code>RewriteCond</code> + directive. The mapping-functions come from the + <code>RewriteMap</code> directive and are explained there. + These three types of variables are expanded in the order of + the above list. + + <p>As already mentioned above, all the rewriting rules are + applied to the <em>Substitution</em> (in the order of + definition in the config file). The URL is <strong>completely + replaced</strong> by the <em>Substitution</em> and the + rewriting process goes on until there are no more rules + unless explicitly terminated by a + <code><strong>L</strong></code> flag - see below.</p> + + <p>There is a special substitution string named + '<code>-</code>' which means: <strong>NO + substitution</strong>! Sounds silly? No, it is useful to + provide rewriting rules which <strong>only</strong> match + some URLs but do no substitution, <em>e.g.</em>, in + conjunction with the <strong>C</strong> (chain) flag to be + able to have more than one pattern to be applied before a + substitution occurs.</p> + + <p>One more note: You can even create URLs in the + substitution string containing a query string part. Just use + a question mark inside the substitution string to indicate + that the following stuff should be re-injected into the + QUERY_STRING. When you want to erase an existing query + string, end the substitution string with just the question + mark.</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Note</strong>: There is a special feature: + When you prefix a substitution field with + <code>http://</code><em>thishost</em>[<em>:thisport</em>] + then <strong>mod_rewrite</strong> automatically strips it + out. This auto-reduction on implicit external redirect + URLs is a useful and important feature when used in + combination with a mapping-function which generates the + hostname part. Have a look at the first example in the + example section below to understand this.</td> + </tr> + </table> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Remember:</strong> An unconditional external + redirect to your own server will not work with the prefix + <code>http://thishost</code> because of this feature. To + achieve such a self-redirect, you have to use the + <strong>R</strong>-flag (see below).</td> + </tr> + </table> + + <p>Additionally you can set special flags for + <em>Substitution</em> by appending</p> + + <blockquote> + <strong><code>[</code><em>flags</em><code>]</code></strong> + </blockquote> + as the third argument to the <code>RewriteRule</code> + directive. <em>Flags</em> is a comma-separated list of the + following flags: + + <ul> + <li> + '<strong><code>redirect|R</code> + [=<em>code</em>]</strong>' (force <a id="redirect" + name="redirect"><strong>r</strong>edirect</a>)<br /> + Prefix <em>Substitution</em> with + <code>http://thishost[:thisport]/</code> (which makes the + new URL a URI) to force a external redirection. If no + <em>code</em> is given a HTTP response of 302 (MOVED + TEMPORARILY) is used. If you want to use other response + codes in the range 300-400 just specify them as a number + or use one of the following symbolic names: + <code>temp</code> (default), <code>permanent</code>, + <code>seeother</code>. Use it for rules which should + canonicalize the URL and give it back to the client, + <em>e.g.</em>, translate ``<code>/~</code>'' into + ``<code>/u/</code>'' or always append a slash to + <code>/u/</code><em>user</em>, etc.<br /> + + + <p><strong>Note:</strong> When you use this flag, make + sure that the substitution field is a valid URL! If not, + you are redirecting to an invalid location! And remember + that this flag itself only prefixes the URL with + <code>http://thishost[:thisport]/</code>, rewriting + continues. Usually you also want to stop and do the + redirection immediately. To stop the rewriting you also + have to provide the 'L' flag.</p> + </li> + + <li>'<strong><code>forbidden|F</code></strong>' (force URL + to be <strong>f</strong>orbidden)<br /> + This forces the current URL to be forbidden, + <em>i.e.</em>, it immediately sends back a HTTP response of + 403 (FORBIDDEN). Use this flag in conjunction with + appropriate RewriteConds to conditionally block some + URLs.</li> + + <li>'<strong><code>gone|G</code></strong>' (force URL to be + <strong>g</strong>one)<br /> + This forces the current URL to be gone, <em>i.e.</em>, it + immediately sends back a HTTP response of 410 (GONE). Use + this flag to mark pages which no longer exist as gone.</li> + + <li> + '<strong><code>proxy|P</code></strong>' (force + <strong>p</strong>roxy)<br /> + This flag forces the substitution part to be internally + forced as a proxy request and immediately (<em>i.e.</em>, + rewriting rule processing stops here) put through the <a + href="mod_proxy.html">proxy module</a>. You have to make + sure that the substitution string is a valid URI + (<em>e.g.</em>, typically starting with + <code>http://</code><em>hostname</em>) which can be + handled by the Apache proxy module. If not you get an + error from the proxy module. Use this flag to achieve a + more powerful implementation of the <a + href="mod_proxy.html#proxypass">ProxyPass</a> directive, + to map some remote stuff into the namespace of the local + server. + + <p>Notice: To use this functionality make sure you have + the proxy module compiled into your Apache server + program. If you don't know please check whether + <code>mod_proxy.c</code> is part of the ``<code>httpd + -l</code>'' output. If yes, this functionality is + available to mod_rewrite. If not, then you first have to + rebuild the ``<code>httpd</code>'' program with mod_proxy + enabled.</p> + </li> + + <li>'<strong><code>last|L</code></strong>' + (<strong>l</strong>ast rule)<br /> + Stop the rewriting process here and don't apply any more + rewriting rules. This corresponds to the Perl + <code>last</code> command or the <code>break</code> command + from the C language. Use this flag to prevent the currently + rewritten URL from being rewritten further by following + rules. For example, use it to rewrite the root-path URL + ('<code>/</code>') to a real one, <em>e.g.</em>, + '<code>/e/www/</code>'.</li> + + <li>'<strong><code>next|N</code></strong>' + (<strong>n</strong>ext round)<br /> + Re-run the rewriting process (starting again with the + first rewriting rule). Here the URL to match is again not + the original URL but the URL from the last rewriting rule. + This corresponds to the Perl <code>next</code> command or + the <code>continue</code> command from the C language. Use + this flag to restart the rewriting process, <em>i.e.</em>, + to immediately go to the top of the loop.<br /> + <strong>But be careful not to create an infinite + loop!</strong></li> + + <li>'<strong><code>chain|C</code></strong>' + (<strong>c</strong>hained with next rule)<br /> + This flag chains the current rule with the next rule + (which itself can be chained with the following rule, + <em>etc.</em>). This has the following effect: if a rule + matches, then processing continues as usual, <em>i.e.</em>, + the flag has no effect. If the rule does + <strong>not</strong> match, then all following chained + rules are skipped. For instance, use it to remove the + ``<code>.www</code>'' part inside a per-directory rule set + when you let an external redirect happen (where the + ``<code>.www</code>'' part should not to occur!).</li> + + <li> + '<strong><code>type|T</code></strong>=<em>MIME-type</em>' + (force MIME <strong>t</strong>ype)<br /> + Force the MIME-type of the target file to be + <em>MIME-type</em>. For instance, this can be used to + simulate the <code>mod_alias</code> directive + <code>ScriptAlias</code> which internally forces all files + inside the mapped directory to have a MIME type of + ``<code>application/x-httpd-cgi</code>''.</li> + + <li> + '<strong><code>nosubreq|NS</code></strong>' (used only if + <strong>n</strong>o internal + <strong>s</strong>ub-request)<br /> + This flag forces the rewriting engine to skip a + rewriting rule if the current request is an internal + sub-request. For instance, sub-requests occur internally + in Apache when <code>mod_include</code> tries to find out + information about possible directory default files + (<code>index.xxx</code>). On sub-requests it is not + always useful and even sometimes causes a failure to if + the complete set of rules are applied. Use this flag to + exclude some rules.<br /> + + + <p>Use the following rule for your decision: whenever you + prefix some URLs with CGI-scripts to force them to be + processed by the CGI-script, the chance is high that you + will run into problems (or even overhead) on + sub-requests. In these cases, use this flag.</p> + </li> + + <li>'<strong><code>nocase|NC</code></strong>' + (<strong>n</strong>o <strong>c</strong>ase)<br /> + This makes the <em>Pattern</em> case-insensitive, + <em>i.e.</em>, there is no difference between 'A-Z' and + 'a-z' when <em>Pattern</em> is matched against the current + URL.</li> + + <li>'<strong><code>qsappend|QSA</code></strong>' + (<strong>q</strong>uery <strong>s</strong>tring + <strong>a</strong>ppend)<br /> + This flag forces the rewriting engine to append a query + string part in the substitution string to the existing one + instead of replacing it. Use this when you want to add more + data to the query string via a rewrite rule.</li> + + <li> + '<strong><code>noescape|NE</code></strong>' + (<strong>n</strong>o URI <strong>e</strong>scaping of + output)<br /> + This flag keeps mod_rewrite from applying the usual URI + escaping rules to the result of a rewrite. Ordinarily, + special characters (such as '%', '$', ';', and so on) + will be escaped into their hexcode equivalents ('%25', + '%24', and '%3B', respectively); this flag prevents this + from being done. This allows percent symbols to appear in + the output, as in +<pre> + RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE] + +</pre> + which would turn '<code>/foo/zed</code>' into a safe + request for '<code>/bar?arg=P1=zed</code>'. + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Notice:</strong> The + <code>noescape</code> flag is only available with + Apache 1.3.20 and later versions.</td> + </tr> + </table> + </li> + + <li> + '<strong><code>passthrough|PT</code></strong>' + (<strong>p</strong>ass <strong>t</strong>hrough to next + handler)<br /> + This flag forces the rewriting engine to set the + <code>uri</code> field of the internal + <code>request_rec</code> structure to the value of the + <code>filename</code> field. This flag is just a hack to + be able to post-process the output of + <code>RewriteRule</code> directives by + <code>Alias</code>, <code>ScriptAlias</code>, + <code>Redirect</code>, <em>etc.</em> directives from + other URI-to-filename translators. A trivial example to + show the semantics: If you want to rewrite + <code>/abc</code> to <code>/def</code> via the rewriting + engine of <code>mod_rewrite</code> and then + <code>/def</code> to <code>/ghi</code> with + <code>mod_alias</code>: +<pre> + RewriteRule ^/abc(.*) /def$1 [PT] + Alias /def /ghi + +</pre> + If you omit the <code>PT</code> flag then + <code>mod_rewrite</code> will do its job fine, + <em>i.e.</em>, it rewrites <code>uri=/abc/...</code> to + <code>filename=/def/...</code> as a full API-compliant + URI-to-filename translator should do. Then + <code>mod_alias</code> comes and tries to do a + URI-to-filename transition which will not work. + + <p>Note: <strong>You have to use this flag if you want to + intermix directives of different modules which contain + URL-to-filename translators</strong>. The typical example + is the use of <code>mod_alias</code> and + <code>mod_rewrite</code>..</p> + </li> + + <li>'<strong><code>skip|S</code></strong>=<em>num</em>' + (<strong>s</strong>kip next rule(s))<br /> + This flag forces the rewriting engine to skip the next + <em>num</em> rules in sequence when the current rule + matches. Use this to make pseudo if-then-else constructs: + The last rule of the then-clause becomes + <code>skip=N</code> where N is the number of rules in the + else-clause. (This is <strong>not</strong> the same as the + 'chain|C' flag!)</li> + + <li> + '<strong><code>env|E=</code></strong><em>VAR</em>:<em>VAL</em>' + (set <strong>e</strong>nvironment variable)<br /> + This forces an environment variable named <em>VAR</em> to + be set to the value <em>VAL</em>, where <em>VAL</em> can + contain regexp backreferences <code>$N</code> and + <code>%N</code> which will be expanded. You can use this + flag more than once to set more than one variable. The + variables can be later dereferenced in many situations, but + usually from within XSSI (via <code><!--#echo + var="VAR"--></code>) or CGI (<em>e.g.</em> + <code>$ENV{'VAR'}</code>). Additionally you can dereference + it in a following RewriteCond pattern via + <code>%{ENV:VAR}</code>. Use this to strip but remember + information from URLs.</li> + </ul> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td> + <strong>Note:</strong> Never forget that + <em>Pattern</em> is applied to a complete URL in + per-server configuration files. <strong>But in + per-directory configuration files, the per-directory + prefix (which always is the same for a specific + directory!) is automatically <em>removed</em> for the + pattern matching and automatically <em>added</em> after + the substitution has been done.</strong> This feature + is essential for many sorts of rewriting, because + without this prefix stripping you have to match the + parent directory which is not always possible. + + <p>There is one exception: If a substitution string + starts with ``<code>http://</code>'' then the directory + prefix will <strong>not</strong> be added and an + external redirect or proxy throughput (if flag + <strong>P</strong> is used!) is forced!</p> + </td> + </tr> + </table> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Note:</strong> To enable the rewriting engine + for per-directory configuration files you need to set + ``<code>RewriteEngine On</code>'' in these files + <strong>and</strong> ``<code>Options + FollowSymLinks</code>'' must be enabled. If your + administrator has disabled override of + <code>FollowSymLinks</code> for a user's directory, then + you cannot use the rewriting engine. This restriction is + needed for security reasons.</td> + </tr> + </table> + + <p>Here are all possible substitution combinations and their + meanings:</p> + + <p><strong>Inside per-server configuration + (<code>httpd.conf</code>)<br /> + for request ``<code>GET + /somepath/pathinfo</code>'':</strong><br /> + </p> + + <table bgcolor="#F0F0F0" cellspacing="0" cellpadding="5"> + <tr> + <td> +<pre> +<strong>Given Rule</strong> <strong>Resulting Substitution</strong> +---------------------------------------------- ---------------------------------- +^/somepath(.*) otherpath$1 not supported, because invalid! + +^/somepath(.*) otherpath$1 [R] not supported, because invalid! + +^/somepath(.*) otherpath$1 [P] not supported, because invalid! +---------------------------------------------- ---------------------------------- +^/somepath(.*) /otherpath$1 /otherpath/pathinfo + +^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo + via external redirection + +^/somepath(.*) /otherpath$1 [P] not supported, because silly! +---------------------------------------------- ---------------------------------- +^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo + +^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo + via external redirection + +^/somepath(.*) http://thishost/otherpath$1 [P] not supported, because silly! +---------------------------------------------- ---------------------------------- +^/somepath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo + via external redirection + +^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo + via external redirection + (the [R] flag is redundant) + +^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo + via internal proxy +</pre> + </td> + </tr> + </table> + + <p><strong>Inside per-directory configuration for + <code>/somepath</code><br /> + (<em>i.e.</em>, file <code>.htaccess</code> in dir + <code>/physical/path/to/somepath</code> containing + <code>RewriteBase /somepath</code>)<br /> + for request ``<code>GET + /somepath/localpath/pathinfo</code>'':</strong><br /> + </p> + + <table bgcolor="#F0F0F0" cellspacing="0" cellpadding="5"> + <tr> + <td> +<pre> +<strong>Given Rule</strong> <strong>Resulting Substitution</strong> +---------------------------------------------- ---------------------------------- +^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo + +^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo + via external redirection + +^localpath(.*) otherpath$1 [P] not supported, because silly! +---------------------------------------------- ---------------------------------- +^localpath(.*) /otherpath$1 /otherpath/pathinfo + +^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo + via external redirection + +^localpath(.*) /otherpath$1 [P] not supported, because silly! +---------------------------------------------- ---------------------------------- +^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo + +^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo + via external redirection + +^localpath(.*) http://thishost/otherpath$1 [P] not supported, because silly! +---------------------------------------------- ---------------------------------- +^localpath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo + via external redirection + +^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo + via external redirection + (the [R] flag is redundant) + +^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo + via internal proxy +</pre> + </td> + </tr> + </table> + + <p><strong>Example:</strong></p> + + <blockquote> + We want to rewrite URLs of the form + + <blockquote> + <code>/</code> <em>Language</em> <code>/~</code> + <em>Realname</em> <code>/.../</code> <em>File</em> + </blockquote> + into + + <blockquote> + <code>/u/</code> <em>Username</em> <code>/.../</code> + <em>File</em> <code>.</code> <em>Language</em> + </blockquote> + + <p>We take the rewrite mapfile from above and save it under + <code>/path/to/file/map.txt</code>. Then we only have to + add the following lines to the Apache server configuration + file:</p> + + <blockquote> +<pre> +RewriteLog /path/to/file/rewrite.log +RewriteMap real-to-user txt:/path/to/file/map.txt +RewriteRule ^/([^/]+)/~([^/]+)/(.*)$ /u/${real-to-user:$2|nobody}/$3.$1 +</pre> + </blockquote> + </blockquote> + <hr noshade="noshade" size="1" /> + + <center> + <h1><a id="Miscelleneous" + name="Miscelleneous">Miscellaneous</a></h1> + </center> + <hr noshade="noshade" size="1" /> + + <h2><a id="EnvVar" name="EnvVar">Environment + Variables</a></h2> + This module keeps track of two additional (non-standard) + CGI/SSI environment variables named <code>SCRIPT_URL</code> + and <code>SCRIPT_URI</code>. These contain the + <em>logical</em> Web-view to the current resource, while the + standard CGI/SSI variables <code>SCRIPT_NAME</code> and + <code>SCRIPT_FILENAME</code> contain the <em>physical</em> + System-view. + + <p>Notice: These variables hold the URI/URL <em>as they were + initially requested</em>, <em>i.e.</em>, <em>before</em> any + rewriting. This is important because the rewriting process is + primarily used to rewrite logical URLs to physical + pathnames.</p> + + <p><strong>Example:</strong></p> + + <blockquote> +<pre> +SCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html +SCRIPT_FILENAME=/u/rse/.www/index.html +SCRIPT_URL=/u/rse/ +SCRIPT_URI=http://en1.engelschall.com/u/rse/ +</pre> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h2><a id="Solutions" name="Solutions">Practical + Solutions</a></h2> + We also have an <a href="../misc/rewriteguide.html">URL + Rewriting Guide</a> available, which provides a collection of + practical solutions for URL-based problems. There you can + find real-life rulesets and additional information about + mod_rewrite. + </blockquote> + <hr /> + + <h3 align="CENTER">Apache HTTP Server Version 1.3</h3> + <a href="./"><img src="../images/index.gif" alt="Index" /></a> + <a href="../"><img src="../images/home.gif" alt="Home" /></a> + + <!-- page indentation --> + <!--/%hypertext --> + </body> +</html> + diff --git a/usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.html b/usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.html new file mode 100644 index 00000000000..61903c9d942 --- /dev/null +++ b/usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.html @@ -0,0 +1,2107 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<!--%hypertext --> +<!-- mod_rewrite.html --> +<!-- Documentation for the mod_rewrite Apache module --> + +<html xmlns="http://www.w3.org/1999/xhtml"> + <head> + <meta name="generator" content="HTML Tidy, see www.w3.org" /> + + <title>Apache module mod_rewrite</title> + </head> + <!-- Background white, links blue (unvisited), navy (visited), red (active) --> + + <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" + vlink="#000080" alink="#FF0000"> + <blockquote> + <!-- page indentation --> + <div align="CENTER"> + <img src="../images/sub.gif" alt="[APACHE DOCUMENTATION]" /> + + <h3>Apache HTTP Server Version 1.3</h3> + </div> + + <br /> + + + <h1 align="CENTER">Module mod_rewrite<br /> + URL Rewriting Engine</h1> + + <p>This module provides a rule-based rewriting engine to + rewrite requested URLs on the fly.</p> + + <p><a href="module-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="module-dict.html#SourceFile" + rel="Help"><strong>Source File:</strong></a> + mod_rewrite.c<br /> + <a href="module-dict.html#ModuleIdentifier" + rel="Help"><strong>Module Identifier:</strong></a> + rewrite_module<br /> + <a href="module-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Available in + Apache 1.2 and later.</p> + <hr noshade="noshade" size="1" /> + <br /> + + + <h2>Summary</h2> + + <blockquote> + <blockquote> + <blockquote> + <em>``The great thing about mod_rewrite is it gives you + all the configurability and flexibility of Sendmail. + The downside to mod_rewrite is that it gives you all + the configurability and flexibility of Sendmail.''</em> + + + <div align="RIGHT"> + -- Brian Behlendorf<br /> + Apache Group + </div> + </blockquote> + </blockquote> + </blockquote> + + <blockquote> + <blockquote> + <blockquote> + <em>`` Despite the tons of examples and docs, + mod_rewrite is voodoo. Damned cool voodoo, but still + voodoo. ''</em> + + <div align="RIGHT"> + -- Brian Moore<br /> + bem@news.cmc.net + </div> + </blockquote> + </blockquote> + </blockquote> + Welcome to mod_rewrite, the Swiss Army Knife of URL + manipulation! + + <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, + for instance server variables, environment variables, HTTP + headers, time stamps and even external database lookups in + various formats can be used to achieve a really granular URL + matching.</p> + + <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 even 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> + + <p>But all this functionality and flexibility has its + drawback: complexity. So don't expect to understand this + entire module in just one day.</p> + + <p>This module was invented and originally written in April + 1996<br /> + and gifted exclusively to the The Apache Group in July 1997 + by</p> + + <blockquote> + <a href="http://www.engelschall.com/"><code>Ralf S. + Engelschall</code></a><br /> + <a + href="mailto:rse@engelschall.com"><code>rse@engelschall.com</code></a><br /> + <a + href="http://www.engelschall.com/"><code>www.engelschall.com</code></a> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h2>Table Of Contents</h2> + + <p><strong>Internal Processing</strong></p> + + <ul> + <li><a href="#InternalAPI">API Phases</a></li> + + <li><a href="#InternalRuleset">Ruleset Processing</a></li> + + <li><a href="#InternalBackRefs">Regex Back-Reference + Availability</a></li> + </ul> + + <p><strong>Configuration Directives</strong></p> + + <ul> + <li><a href="#RewriteEngine">RewriteEngine</a></li> + + <li><a href="#RewriteOptions">RewriteOptions</a></li> + + <li><a href="#RewriteLog">RewriteLog</a></li> + + <li><a href="#RewriteLogLevel">RewriteLogLevel</a></li> + + <li><a href="#RewriteLock">RewriteLock</a></li> + + <li><a href="#RewriteMap">RewriteMap</a></li> + + <li><a href="#RewriteBase">RewriteBase</a></li> + + <li><a href="#RewriteCond">RewriteCond</a></li> + + <li><a href="#RewriteRule">RewriteRule</a></li> + </ul> + <strong>Miscellaneous</strong> + + <ul> + <li><a href="#EnvVar">Environment Variables</a></li> + + <li><a href="#Solutions">Practical Solutions</a></li> + </ul> + <hr noshade="noshade" size="1" /> + + <center> + <h1><a id="Internal" name="Internal">Internal + Processing</a></h1> + </center> + <hr noshade="noshade" size="1" /> + + <p>The internal processing of this module is very complex but + needs to be explained once even to the average user to avoid + common mistakes and to let you exploit its full + functionality.</p> + + <h2><a id="InternalAPI" name="InternalAPI">API + Phases</a></h2> + + <p>First you have to understand that when Apache processes a + HTTP request it does this in phases. A hook for each of these + phases is provided by the Apache API. Mod_rewrite uses two of + these hooks: the URL-to-filename translation hook which is + used after the HTTP request has been read but before any + authorization starts and the Fixup hook which is triggered + after the authorization phases and after the per-directory + config files (<code>.htaccess</code>) have been read, but + before the content handler is activated.</p> + + <p>So, after a request comes in and Apache has determined the + corresponding server (or virtual server) the rewriting engine + starts processing of all mod_rewrite directives from the + per-server configuration in the URL-to-filename phase. A few + steps later when the final data directories are found, the + per-directory configuration directives of mod_rewrite are + triggered in the Fixup phase. In both situations mod_rewrite + rewrites URLs either to new URLs or to filenames, although + there is no obvious distinction between them. This is a usage + of the API which was not intended to be this way when the API + was designed, but as of Apache 1.x this is the only way + mod_rewrite can operate. To make this point more clear + remember the following two points:</p> + + <ol> + <li>Although mod_rewrite rewrites URLs to URLs, URLs to + filenames and even filenames to filenames, the API + currently provides only a URL-to-filename hook. In Apache + 2.0 the two missing hooks will be added to make the + processing more clear. But this point has no drawbacks for + the user, it is just a fact which should be remembered: + Apache does more in the URL-to-filename hook than the API + intends for it.</li> + + <li> + Unbelievably mod_rewrite provides URL manipulations in + per-directory context, <em>i.e.</em>, within + <code>.htaccess</code> files, although these are reached + a very long time after the URLs have been translated to + filenames. It has to be this way because + <code>.htaccess</code> files live in the filesystem, so + processing has already reached this stage. In other + words: According to the API phases at this time it is too + late for any URL manipulations. To overcome this chicken + and egg problem mod_rewrite uses a trick: When you + manipulate a URL/filename in per-directory context + mod_rewrite first rewrites the filename back to its + corresponding URL (which is usually impossible, but see + the <code>RewriteBase</code> directive below for the + trick to achieve this) and then initiates a new internal + sub-request with the new URL. This restarts processing of + the API phases. + + <p>Again mod_rewrite tries hard to make this complicated + step totally transparent to the user, but you should + remember here: While URL manipulations in per-server + context are really fast and efficient, per-directory + rewrites are slow and inefficient due to this chicken and + egg problem. But on the other hand this is the only way + mod_rewrite can provide (locally restricted) URL + manipulations to the average user.</p> + </li> + </ol> + + <p>Don't forget these two points!</p> + + <h2><a id="InternalRuleset" name="InternalRuleset">Ruleset + Processing</a></h2> + Now when mod_rewrite is triggered in these two API phases, it + reads the configured rulesets from its configuration + structure (which itself was either created on startup for + per-server context or during the directory walk of the Apache + kernel for per-directory context). Then the URL rewriting + engine is started with the contained ruleset (one or more + rules together with their conditions). The operation of the + URL rewriting engine itself is exactly the same for both + configuration contexts. Only the final result processing is + different. + + <p>The order of rules in the ruleset is important because the + rewriting engine processes them in a special (and not very + obvious) order. The rule is this: The rewriting engine loops + through the ruleset rule by rule (<code>RewriteRule</code> + directives) and when a particular rule matches it optionally + loops through existing corresponding conditions + (<code>RewriteCond</code> directives). For historical reasons + the conditions are given first, and so the control flow is a + little bit long-winded. See Figure 1 for more details.</p> + + <div align="CENTER"> + <table cellspacing="0" cellpadding="2" border="0"> + <tr> + <td bgcolor="#CCCCCC"><img + src="../images/mod_rewrite_fig1.gif" width="428" + height="385" + alt="[Needs graphics capability to display]" /></td> + </tr> + + <tr> + <td align="CENTER"><strong>Figure 1:</strong> The + control flow through the rewriting ruleset</td> + </tr> + </table> + </div> + + <p>As you can see, first the URL is matched against the + <em>Pattern</em> of each rule. When it fails mod_rewrite + immediately stops processing this rule and continues with the + next rule. If the <em>Pattern</em> matches, mod_rewrite looks + for corresponding rule conditions. If none are present, it + just substitutes the URL with a new value which is + constructed from the string <em>Substitution</em> and goes on + with its rule-looping. But if conditions exist, it starts an + inner loop for processing them in the order that they are + listed. For conditions the logic is different: we don't match + a pattern against the current URL. Instead we first create a + string <em>TestString</em> by expanding variables, + back-references, map lookups, <em>etc.</em> and then we try + to match <em>CondPattern</em> against it. If the pattern + doesn't match, the complete set of conditions and the + corresponding rule fails. If the pattern matches, then the + next condition is processed until no more conditions are + available. If all conditions match, processing is continued + with the substitution of the URL with + <em>Substitution</em>.</p> + + <h2><a id="quoting" name="quoting">Quoting Special + Characters</a></h2> + + <p>As of Apache 1.3.20, special characters in + <i>TestString</i> and <i>Substitution</i> strings can be + escaped (that is, treated as normal characters without their + usual special meaning) by prefixing them with a slosh ('\') + character. In other words, you can include an actual + dollar-sign character in a <i>Substitution</i> string by + using '<code>\$</code>'; this keeps mod_rewrite from trying + to treat it as a backreference.</p> + + <h2><a id="InternalBackRefs" name="InternalBackRefs">Regex + Back-Reference Availability</a></h2> + One important thing here has to be remembered: Whenever you + use parentheses in <em>Pattern</em> or in one of the + <em>CondPattern</em>, back-references are internally created + which can be used with the strings <code>$N</code> and + <code>%N</code> (see below). These are available for creating + the strings <em>Substitution</em> and <em>TestString</em>. + Figure 2 shows to which locations the back-references are + transfered for expansion. + + <div align="CENTER"> + <table cellspacing="0" cellpadding="2" border="0"> + <tr> + <td bgcolor="#CCCCCC"><img + src="../images/mod_rewrite_fig2.gif" width="381" + height="179" + alt="[Needs graphics capability to display]" /></td> + </tr> + + <tr> + <td align="CENTER"><strong>Figure 2:</strong> The + back-reference flow through a rule</td> + </tr> + </table> + </div> + + <p>We know this was a crash course on mod_rewrite's internal + processing. But you will benefit from this knowledge when + reading the following documentation of the available + directives.</p> + <hr noshade="noshade" size="1" /> + + <center> + <h1><a id="Configuration" + name="Configuration">Configuration Directives</a></h1> + </center> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteEngine" + name="RewriteEngine">RewriteEngine</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteEngine + on|off<br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <code>RewriteEngine + off</code><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host, directory, .htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> FileInfo<br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache + 1.2<br /> + + + <p>The <code>RewriteEngine</code> directive enables or + disables the runtime rewriting engine. If it is set to + <code>off</code> this module does no runtime processing at + all. It does not even update the <code>SCRIPT_URx</code> + environment variables.</p> + + <p>Use this directive to disable the module instead of + commenting out all the <code>RewriteRule</code> + directives!</p> + + <p>Note that, by default, rewrite configurations are not + inherited. This means that you need to have a + <code>RewriteEngine on</code> directive for each virtual host + in which you wish to use it.</p> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteOptions" + name="RewriteOptions">RewriteOptions</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteOptions + <em>Option</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <code>RewriteOptions + MaxRedirects=10</code><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host, directory, .htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> FileInfo<br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache + 1.2; <code>MaxRedirects</code> is available in Apache 1.3.28 and + later<br /> + + + <p>The <code>RewriteOptions</code> directive sets some + special options for the current per-server or per-directory + configuration. The <em>Option</em> strings can be one of the + following:</p> + + <dl> + <dt><code>inherit</code></dt> + <dd>This forces the current configuration to inherit the + configuration of the parent. In per-virtual-server context + this means that the maps, conditions and rules of the main + server are inherited. In per-directory context this means + that conditions and rules of the parent directory's + <code>.htaccess</code> configuration are inherited.</dd> + + <dt><code>MaxRedirects=<var>number</var></code></dt> + <dd>In order to prevent endless loops of internal redirects + issued by per-directory <code>RewriteRule</code>s, + <code>mod_rewrite</code> aborts the request after reaching a + maximum number of such redirects and responds with an 500 Internal + Server Error. If you really need more internal redirects than 10 + per request, you may increase the default to the desired value.</dd> + </dl> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteLog" name="RewriteLog">RewriteLog</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteLog + <em>file-path</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <em>None</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> <em>Not + applicable</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache + 1.2<br /> + + + <p>The <code>RewriteLog</code> directive sets the name of the + file to which the server logs any rewriting actions it + performs. If the name does not begin with a slash + ('<code>/</code>') then it is assumed to be relative to the + <em>Server Root</em>. The directive should occur only once + per server config.</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Note</strong>: To disable the logging of + rewriting actions it is not recommended to set + <em>file-path</em> to <code>/dev/null</code>, because + although the rewriting engine does not then output to a + logfile it still creates the logfile output internally. + <strong>This will slow down the server with no advantage + to the administrator!</strong> To disable logging either + remove or comment out the <code>RewriteLog</code> + directive or use <code>RewriteLogLevel 0</code>!</td> + </tr> + </table> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Security</strong>: See the <a + href="../misc/security_tips.html">Apache Security + Tips</a> document for details on why your security could + be compromised if the directory where logfiles are stored + is writable by anyone other than the user that starts the + server.</td> + </tr> + </table> + + <p><strong>Example:</strong></p> + + <blockquote> +<pre> +RewriteLog "/usr/local/var/apache/logs/rewrite.log" +</pre> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteLogLevel" + name="RewriteLogLevel">RewriteLogLevel</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteLogLevel + <em>Level</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> + <code>RewriteLogLevel 0</code><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> <em>Not + applicable</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache + 1.2<br /> + + + <p>The <code>RewriteLogLevel</code> directive sets the + verbosity level of the rewriting logfile. The default level 0 + means no logging, while 9 or more means that practically all + actions are logged.</p> + + <p>To disable the logging of rewriting actions simply set + <em>Level</em> to 0. This disables all rewrite action + logs.</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Notice:</strong> Using a high value for + <em>Level</em> will slow down your Apache server + dramatically! Use the rewriting logfile at a + <em>Level</em> greater than 2 only for debugging!</td> + </tr> + </table> + + <p><strong>Example:</strong></p> + + <blockquote> +<pre> +RewriteLogLevel 3 +</pre> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteLock" + name="RewriteLock">RewriteLock</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteLock + <em>file-path</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <em>None</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> <em>Not + applicable</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache + 1.3<br /> + + + <p>This directive sets the filename for a synchronization + lockfile which mod_rewrite needs to communicate with + <samp>RewriteMap</samp> <em>programs</em>. Set this lockfile + to a local path (not on a NFS-mounted device) when you want + to use a rewriting map-program. It is not required for other + types of rewriting maps.</p> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteMap" name="RewriteMap">RewriteMap</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteMap + <em>MapName</em> <em>MapType</em>:<em>MapSource</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> not used per + default<br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> <em>Not + applicable</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache 1.2 + (partially), Apache 1.3<br /> + + + <p>The <code>RewriteMap</code> directive defines a + <em>Rewriting Map</em> which can be used inside rule + substitution strings by the mapping-functions to + insert/substitute fields through a key lookup. The source of + this lookup can be of various types.</p> + + <p>The <a id="mapfunc" name="mapfunc"><em>MapName</em></a> is + the name of the map and will be used to specify a + mapping-function for the substitution strings of a rewriting + rule via one of the following constructs:</p> + + <blockquote> + <strong><code>${</code> <em>MapName</em> <code>:</code> + <em>LookupKey</em> <code>}</code><br /> + <code>${</code> <em>MapName</em> <code>:</code> + <em>LookupKey</em> <code>|</code> <em>DefaultValue</em> + <code>}</code></strong> + </blockquote> + When such a construct occurs the map <em>MapName</em> is + consulted and the key <em>LookupKey</em> is looked-up. If the + key is found, the map-function construct is substituted by + <em>SubstValue</em>. If the key is not found then it is + substituted by <em>DefaultValue</em> or by the empty string + if no <em>DefaultValue</em> was specified. + + <p>The following combinations for <em>MapType</em> and + <em>MapSource</em> can be used:</p> + + <ul> + <li> + <strong>Standard Plain Text</strong><br /> + MapType: <code>txt</code>, MapSource: Unix filesystem + path to valid regular file + + <p>This is the standard rewriting map feature where the + <em>MapSource</em> is a plain ASCII file containing + either blank lines, comment lines (starting with a '#' + character) or pairs like the following - one per + line.</p> + + <blockquote> + <strong><em>MatchingKey</em> + <em>SubstValue</em></strong> + </blockquote> + + <p>Example:</p> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +## +## map.txt -- rewriting map +## + +Ralf.S.Engelschall rse # Bastard Operator From Hell +Mr.Joe.Average joe # Mr. Average +</pre> + </td> + </tr> + </table> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +RewriteMap real-to-user txt:/path/to/file/map.txt +</pre> + </td> + </tr> + </table> + </li> + + <li> + <strong>Randomized Plain Text</strong><br /> + MapType: <code>rnd</code>, MapSource: Unix filesystem + path to valid regular file + + <p>This is identical to the Standard Plain Text variant + above but with a special post-processing feature: After + looking up a value it is parsed according to contained + ``<code>|</code>'' characters which have the meaning of + ``or''. In other words they indicate a set of + alternatives from which the actual returned value is + chosen randomly. Although this sounds crazy and useless, + it was actually designed for load balancing in a reverse + proxy situation where the looked up values are server + names. Example:</p> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +## +## map.txt -- rewriting map +## + +static www1|www2|www3|www4 +dynamic www5|www6 +</pre> + </td> + </tr> + </table> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +RewriteMap servers rnd:/path/to/file/map.txt +</pre> + </td> + </tr> + </table> + </li> + + <li> + <strong>Hash File</strong><br /> + MapType: <code>dbm</code>, MapSource: Unix filesystem + path to valid regular file + + <p>Here the source is a binary NDBM format file + containing the same contents as a <em>Plain Text</em> + format file, but in a special representation which is + optimized for really fast lookups. You can create such a + file with any NDBM tool or with the following Perl + script:</p> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +#!/path/to/bin/perl +## +## txt2dbm -- convert txt map to dbm format +## + +use NDBM_File; +use Fcntl; + +($txtmap, $dbmmap) = @ARGV; + +open(TXT, "<$txtmap") or die "Couldn't open $txtmap!\n"; +tie (%DB, 'NDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644) or die "Couldn't create $dbmmap!\n"; + +while (<TXT>) { + next if (/^\s*#/ or /^\s*$/); + $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/); +} + +untie %DB; +close(TXT); +</pre> + </td> + </tr> + </table> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +$ txt2dbm map.txt map.db +</pre> + </td> + </tr> + </table> + </li> + + <li> + <strong>Internal Function</strong><br /> + MapType: <code>int</code>, MapSource: Internal Apache + function + + <p>Here the source is an internal Apache function. + Currently you cannot create your own, but the following + functions already exists:</p> + + <ul> + <li><strong>toupper</strong>:<br /> + Converts the looked up key to all upper case.</li> + + <li><strong>tolower</strong>:<br /> + Converts the looked up key to all lower case.</li> + + <li><strong>escape</strong>:<br /> + Translates special characters in the looked up key to + hex-encodings.</li> + + <li><strong>unescape</strong>:<br /> + Translates hex-encodings in the looked up key back to + special characters.</li> + </ul> + </li> + + <li> + <strong>External Rewriting Program</strong><br /> + MapType: <code>prg</code>, MapSource: Unix filesystem + path to valid regular file + + <p>Here the source is a program, not a map file. To + create it you can use the language of your choice, but + the result has to be a executable (<em>i.e.</em>, either + object-code or a script with the magic cookie trick + '<code>#!/path/to/interpreter</code>' as the first + line).</p> + + <p>This program is started once at startup of the Apache + servers and then communicates with the rewriting engine + over its <code>stdin</code> and <code>stdout</code> + file-handles. For each map-function lookup it will + receive the key to lookup as a newline-terminated string + on <code>stdin</code>. It then has to give back the + looked-up value as a newline-terminated string on + <code>stdout</code> or the four-character string + ``<code>NULL</code>'' if it fails (<em>i.e.</em>, there + is no corresponding value for the given key). A trivial + program which will implement a 1:1 map (<em>i.e.</em>, + key == value) could be:</p> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +#!/usr/bin/perl +$| = 1; +while (<STDIN>) { + # ...put here any transformations or lookups... + print $_; +} +</pre> + </td> + </tr> + </table> + + <p>But be very careful:<br /> + </p> + + <ol> + <li>``<em>Keep it simple, stupid</em>'' (KISS), because + if this program hangs it will hang the Apache server + when the rule occurs.</li> + + <li>Avoid one common mistake: never do buffered I/O on + <code>stdout</code>! This will cause a deadloop! Hence + the ``<code>$|=1</code>'' in the above example...</li> + + <li>Use the <samp>RewriteLock</samp> directive to + define a lockfile mod_rewrite can use to synchronize + the communication to the program. By default no such + synchronization takes place.</li> + </ol> + </li> + </ul> + The <code>RewriteMap</code> directive can occur more than + once. For each mapping-function use one + <code>RewriteMap</code> directive to declare its rewriting + mapfile. While you cannot <strong>declare</strong> a map in + per-directory context it is of course possible to + <strong>use</strong> this map in per-directory context. + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Note:</strong> For plain text and DBM format + files the looked-up keys are cached in-core until the + <code>mtime</code> of the mapfile changes or the server + does a restart. This way you can have map-functions in + rules which are used for <strong>every</strong> request. + This is no problem, because the external lookup only + happens once!</td> + </tr> + </table> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteBase" + name="RewriteBase">RewriteBase</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteBase + <em>URL-path</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <em>default is the + physical directory path</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> directory, + .htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> + <em>FileInfo</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache + 1.2<br /> + + + <p>The <code>RewriteBase</code> directive explicitly sets the + base URL for per-directory rewrites. As you will see below, + <code>RewriteRule</code> can be used in per-directory config + files (<code>.htaccess</code>). There it will act locally, + <em>i.e.</em>, the local directory prefix is stripped at this + stage of processing and your rewriting rules act only on the + remainder. At the end it is automatically added back to the + path.</p> + + <p>When a substitution occurs for a new URL, this module has + to re-inject the URL into the server processing. To be able + to do this it needs to know what the corresponding URL-prefix + or URL-base is. By default this prefix is the corresponding + filepath itself. <strong>But at most websites URLs are NOT + directly related to physical filename paths, so this + assumption will usually be wrong!</strong> There you have to + use the <code>RewriteBase</code> directive to specify the + correct URL-prefix.</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Notice:</strong> If your webserver's URLs are + <strong>not</strong> directly related to physical file + paths, you have to use <code>RewriteBase</code> in every + <code>.htaccess</code> files where you want to use + <code>RewriteRule</code> directives.</td> + </tr> + </table> + + <p><strong>Example:</strong></p> + + <blockquote> + Assume the following per-directory config file: + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +# +# /abc/def/.htaccess -- per-dir config file for directory /abc/def +# Remember: /abc/def is the physical path of /xyz, <em>i.e.</em>, the server +# has a 'Alias /xyz /abc/def' directive <em>e.g.</em> +# + +RewriteEngine On + +# let the server know that we were reached via /xyz and not +# via the physical path prefix /abc/def +RewriteBase /xyz + +# now the rewriting rules +RewriteRule ^oldstuff\.html$ newstuff.html +</pre> + </td> + </tr> + </table> + + <p>In the above example, a request to + <code>/xyz/oldstuff.html</code> gets correctly rewritten to + the physical file <code>/abc/def/newstuff.html</code>.</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td> + <font size="-1"><strong>Note - For Apache + hackers:</strong><br /> + The following list gives detailed information about + the internal processing steps:</font> +<pre> +<font size="-1">Request: + /xyz/oldstuff.html + +Internal Processing: + /xyz/oldstuff.html -> /abc/def/oldstuff.html (per-server Alias) + /abc/def/oldstuff.html -> /abc/def/newstuff.html (per-dir RewriteRule) + /abc/def/newstuff.html -> /xyz/newstuff.html (per-dir RewriteBase) + /xyz/newstuff.html -> /abc/def/newstuff.html (per-server Alias) + +Result: + /abc/def/newstuff.html +</font> +</pre> + <font size="-1">This seems very complicated but is + the correct Apache internal processing, because the + per-directory rewriting comes too late in the + process. So, when it occurs the (rewritten) request + has to be re-injected into the Apache kernel! BUT: + While this seems like a serious overhead, it really + isn't, because this re-injection happens fully + internally to the Apache server and the same + procedure is used by many other operations inside + Apache. So, you can be sure the design and + implementation is correct.</font> + </td> + </tr> + </table> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteCond" + name="RewriteCond">RewriteCond</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteCond + <em>TestString</em> <em>CondPattern</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <em>None</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host, directory, .htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> + <em>FileInfo</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache 1.2 + (partially), Apache 1.3<br /> + + + <p>The <code>RewriteCond</code> directive defines a rule + condition. Precede a <code>RewriteRule</code> directive with + one or more <code>RewriteCond</code> directives. The + following rewriting rule is only used if its pattern matches + the current state of the URI <strong>and</strong> if these + additional conditions apply too.</p> + + <p><em>TestString</em> is a string which can contains the + following expanded constructs in addition to plain text:</p> + + <ul> + <li> + <strong>RewriteRule backreferences</strong>: These are + backreferences of the form + + <blockquote> + <strong><code>$N</code></strong> + </blockquote> + (0 <= N <= 9) which provide access to the grouped + parts (parenthesis!) of the pattern from the + corresponding <code>RewriteRule</code> directive (the one + following the current bunch of <code>RewriteCond</code> + directives). + </li> + + <li> + <strong>RewriteCond backreferences</strong>: These are + backreferences of the form + + <blockquote> + <strong><code>%N</code></strong> + </blockquote> + (1 <= N <= 9) which provide access to the grouped + parts (parentheses!) of the pattern from the last matched + <code>RewriteCond</code> directive in the current bunch + of conditions. + </li> + + <li> + <strong>RewriteMap expansions</strong>: These are + expansions of the form + + <blockquote> + <strong><code>${mapname:key|default}</code></strong> + </blockquote> + See <a href="#mapfunc">the documentation for + RewriteMap</a> for more details. + </li> + + <li> + <strong>Server-Variables</strong>: These are variables of + the form + + <blockquote> + <strong><code>%{</code> <em>NAME_OF_VARIABLE</em> + <code>}</code></strong> + </blockquote> + where <em>NAME_OF_VARIABLE</em> can be a string taken + from the following list: + + <table bgcolor="#F0F0F0" cellspacing="0" cellpadding="5"> + <tr> + <td valign="TOP"> + <strong>HTTP headers:</strong> + + <p><font size="-1">HTTP_USER_AGENT<br /> + HTTP_REFERER<br /> + HTTP_COOKIE<br /> + HTTP_FORWARDED<br /> + HTTP_HOST<br /> + HTTP_PROXY_CONNECTION<br /> + HTTP_ACCEPT<br /> + </font></p> + </td> + + <td valign="TOP"> + <strong>connection & request:</strong> + + <p><font size="-1">REMOTE_ADDR<br /> + REMOTE_HOST<br /> + REMOTE_USER<br /> + REMOTE_IDENT<br /> + REQUEST_METHOD<br /> + SCRIPT_FILENAME<br /> + PATH_INFO<br /> + QUERY_STRING<br /> + AUTH_TYPE<br /> + </font></p> + </td> + </tr> + + <tr> + <td valign="TOP"> + <strong>server internals:</strong> + + <p><font size="-1">DOCUMENT_ROOT<br /> + SERVER_ADMIN<br /> + SERVER_NAME<br /> + SERVER_ADDR<br /> + SERVER_PORT<br /> + SERVER_PROTOCOL<br /> + SERVER_SOFTWARE<br /> + </font></p> + </td> + + <td valign="TOP"> + <strong>system stuff:</strong> + + <p><font size="-1">TIME_YEAR<br /> + TIME_MON<br /> + TIME_DAY<br /> + TIME_HOUR<br /> + TIME_MIN<br /> + TIME_SEC<br /> + TIME_WDAY<br /> + TIME<br /> + </font></p> + </td> + + <td valign="TOP"> + <strong>specials:</strong> + + <p><font size="-1">API_VERSION<br /> + THE_REQUEST<br /> + REQUEST_URI<br /> + REQUEST_FILENAME<br /> + IS_SUBREQ<br /> + </font></p> + </td> + </tr> + </table> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td> + <p><strong>Notice:</strong> These variables all + correspond to the similarly named HTTP + MIME-headers, C variables of the Apache server or + <code>struct tm</code> fields of the Unix system. + Most are documented elsewhere in the Manual or in + the CGI specification. Those that are special to + mod_rewrite include:</p> + + <dl> + <dt><code>IS_SUBREQ</code></dt> + + <dd>Will contain the text "true" if the request + currently being processed is a sub-request, + "false" otherwise. Sub-requests may be generated + by modules that need to resolve additional files + or URIs in order to complete their tasks.</dd> + + <dt><code>API_VERSION</code></dt> + + <dd>This is the version of the Apache module API + (the internal interface between server and + module) in the current httpd build, as defined in + include/ap_mmn.h. The module API version + corresponds to the version of Apache in use (in + the release version of Apache 1.3.14, for + instance, it is 19990320:10), but is mainly of + interest to module authors.</dd> + + <dt><code>THE_REQUEST</code></dt> + + <dd>The full HTTP request line sent by the + browser to the server (e.g., "<code>GET + /index.html HTTP/1.1</code>"). This does not + include any additional headers sent by the + browser.</dd> + + <dt><code>REQUEST_URI</code></dt> + + <dd>The resource requested in the HTTP request + line. (In the example above, this would be + "/index.html".)</dd> + + <dt><code>REQUEST_FILENAME</code></dt> + + <dd>The full local filesystem path to the file or + script matching the request.</dd> + </dl> + </td> + </tr> + </table> + </li> + </ul> + + <p>Special Notes:</p> + + <ol> + <li>The variables SCRIPT_FILENAME and REQUEST_FILENAME + contain the same value, <em>i.e.</em>, the value of the + <code>filename</code> field of the internal + <code>request_rec</code> structure of the Apache server. + The first name is just the commonly known CGI variable name + while the second is the consistent counterpart to + REQUEST_URI (which contains the value of the + <code>uri</code> field of <code>request_rec</code>).</li> + + <li>There is the special format: + <code>%{ENV:variable}</code> where <em>variable</em> can be + any environment variable. This is looked-up via internal + Apache structures and (if not found there) via + <code>getenv()</code> from the Apache server process.</li> + + <li>There is the special format: + <code>%{HTTP:header}</code> where <em>header</em> can be + any HTTP MIME-header name. This is looked-up from the HTTP + request. Example: <code>%{HTTP:Proxy-Connection}</code> is + the value of the HTTP header + ``<code>Proxy-Connection:</code>''.</li> + + <li>There is the special format + <code>%{LA-U:variable}</code> for look-aheads which perform + an internal (URL-based) sub-request to determine the final + value of <em>variable</em>. Use this when you want to use a + variable for rewriting which is actually set later in an + API phase and thus is not available at the current stage. + For instance when you want to rewrite according to the + <code>REMOTE_USER</code> variable from within the + per-server context (<code>httpd.conf</code> file) you have + to use <code>%{LA-U:REMOTE_USER}</code> because this + variable is set by the authorization phases which come + <em>after</em> the URL translation phase where mod_rewrite + operates. On the other hand, because mod_rewrite implements + its per-directory context (<code>.htaccess</code> file) via + the Fixup phase of the API and because the authorization + phases come <em>before</em> this phase, you just can use + <code>%{REMOTE_USER}</code> there.</li> + + <li>There is the special format: + <code>%{LA-F:variable}</code> which performs an internal + (filename-based) sub-request to determine the final value + of <em>variable</em>. Most of the time this is the same as + LA-U above.</li> + </ol> + + <p><em>CondPattern</em> is the condition pattern, + <em>i.e.</em>, a regular expression which is applied to the + current instance of the <em>TestString</em>, <em>i.e.</em>, + <em>TestString</em> is evaluated and then matched against + <em>CondPattern</em>.</p> + + <p><strong>Remember:</strong> <em>CondPattern</em> is a + standard <em>Extended Regular Expression</em> with some + additions:</p> + + <ol> + <li>You can prefix the pattern string with a + '<code>!</code>' character (exclamation mark) to specify a + <strong>non</strong>-matching pattern.</li> + + <li> + There are some special variants of <em>CondPatterns</em>. + Instead of real regular expression strings you can also + use one of the following: + + <ul> + <li>'<strong><CondPattern</strong>' (is lexically + lower)<br /> + Treats the <em>CondPattern</em> as a plain string and + compares it lexically to <em>TestString</em>. True if + <em>TestString</em> is lexically lower than + <em>CondPattern</em>.</li> + + <li>'<strong>>CondPattern</strong>' (is lexically + greater)<br /> + Treats the <em>CondPattern</em> as a plain string and + compares it lexically to <em>TestString</em>. True if + <em>TestString</em> is lexically greater than + <em>CondPattern</em>.</li> + + <li>'<strong>=CondPattern</strong>' (is lexically + equal)<br /> + Treats the <em>CondPattern</em> as a plain string and + compares it lexically to <em>TestString</em>. True if + <em>TestString</em> is lexically equal to + <em>CondPattern</em>, i.e the two strings are exactly + equal (character by character). If <em>CondPattern</em> + is just <samp>""</samp> (two quotation marks) this + compares <em>TestString</em> to the empty string.</li> + + <li>'<strong>-d</strong>' (is + <strong>d</strong>irectory)<br /> + Treats the <em>TestString</em> as a pathname and tests + if it exists and is a directory.</li> + + <li>'<strong>-f</strong>' (is regular + <strong>f</strong>ile)<br /> + Treats the <em>TestString</em> as a pathname and tests + if it exists and is a regular file.</li> + + <li>'<strong>-s</strong>' (is regular file with + <strong>s</strong>ize)<br /> + Treats the <em>TestString</em> as a pathname and tests + if it exists and is a regular file with size greater + than zero.</li> + + <li>'<strong>-l</strong>' (is symbolic + <strong>l</strong>ink)<br /> + Treats the <em>TestString</em> as a pathname and tests + if it exists and is a symbolic link.</li> + + <li>'<strong>-F</strong>' (is existing file via + subrequest)<br /> + Checks if <em>TestString</em> is a valid file and + accessible via all the server's currently-configured + access controls for that path. This uses an internal + subrequest to determine the check, so use it with care + because it decreases your servers performance!</li> + + <li>'<strong>-U</strong>' (is existing URL via + subrequest)<br /> + Checks if <em>TestString</em> is a valid URL and + accessible via all the server's currently-configured + access controls for that path. This uses an internal + subrequest to determine the check, so use it with care + because it decreases your server's performance!</li> + </ul> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Notice:</strong> All of these tests can + also be prefixed by an exclamation mark ('!') to + negate their meaning.</td> + </tr> + </table> + </li> + </ol> + + <p>Additionally you can set special flags for + <em>CondPattern</em> by appending</p> + + <blockquote> + <strong><code>[</code><em>flags</em><code>]</code></strong> + </blockquote> + as the third argument to the <code>RewriteCond</code> + directive. <em>Flags</em> is a comma-separated list of the + following flags: + + <ul> + <li>'<strong><code>nocase|NC</code></strong>' + (<strong>n</strong>o <strong>c</strong>ase)<br /> + This makes the test case-insensitive, <em>i.e.</em>, there + is no difference between 'A-Z' and 'a-z' both in the + expanded <em>TestString</em> and the <em>CondPattern</em>. + This flag is effective only for comparisons between + <em>TestString</em> and <em>CondPattern</em>. It has no + effect on filesystem and subrequest checks.</li> + + <li> + '<strong><code>ornext|OR</code></strong>' + (<strong>or</strong> next condition)<br /> + Use this to combine rule conditions with a local OR + instead of the implicit AND. Typical example: + + <blockquote> +<pre> +RewriteCond %{REMOTE_HOST} ^host1.* [OR] +RewriteCond %{REMOTE_HOST} ^host2.* [OR] +RewriteCond %{REMOTE_HOST} ^host3.* +RewriteRule ...some special stuff for any of these hosts... +</pre> + </blockquote> + Without this flag you would have to write the cond/rule + three times. + </li> + </ul> + + <p><strong>Example:</strong></p> + + <blockquote> + To rewrite the Homepage of a site according to the + ``<code>User-Agent:</code>'' header of the request, you can + use the following: + + <blockquote> +<pre> +RewriteCond %{HTTP_USER_AGENT} ^Mozilla.* +RewriteRule ^/$ /homepage.max.html [L] + +RewriteCond %{HTTP_USER_AGENT} ^Lynx.* +RewriteRule ^/$ /homepage.min.html [L] + +RewriteRule ^/$ /homepage.std.html [L] +</pre> + </blockquote> + Interpretation: If you use Netscape Navigator as your + browser (which identifies itself as 'Mozilla'), then you + get the max homepage, which includes Frames, <em>etc.</em> + If you use the Lynx browser (which is Terminal-based), then + you get the min homepage, which contains no images, no + tables, <em>etc.</em> If you use any other browser you get + the standard homepage. + </blockquote> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteRule" + name="RewriteRule">RewriteRule</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>Syntax:</strong></a> RewriteRule + <em>Pattern</em> <em>Substitution</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>Default:</strong></a> <em>None</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>Context:</strong></a> server config, + virtual host, directory, .htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>Override:</strong></a> + <em>FileInfo</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>Status:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>Module:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>Compatibility:</strong></a> Apache 1.2 + (partially), Apache 1.3<br /> + + + <p>The <code>RewriteRule</code> directive is the real + rewriting workhorse. The directive can occur more than once. + Each directive then defines one single rewriting rule. The + <strong>definition order</strong> of these rules is + <strong>important</strong>, because this order is used when + applying the rules at run-time.</p> + + <p><a id="patterns" name="patterns"><em>Pattern</em></a> can + be (for Apache 1.1.x a System V8 and for Apache 1.2.x and + later a POSIX) <a id="regexp" name="regexp">regular + expression</a> which gets applied to the current URL. Here + ``current'' means the value of the URL when this rule gets + applied. This may not be the originally requested URL, + because any number of rules may already + have matched and made alterations to it.</p> + + <p>Some hints about the syntax of regular expressions:</p> + + <table bgcolor="#F0F0F0" cellspacing="0" cellpadding="5"> + <tr> + <td valign="TOP"> +<pre> +<strong>Text:</strong> + <strong><code>.</code></strong> Any single character + <strong><code>[</code></strong>chars<strong><code>]</code></strong> Character class: One of chars + <strong><code>[^</code></strong>chars<strong><code>]</code></strong> Character class: None of chars + text1<strong><code>|</code></strong>text2 Alternative: text1 or text2 + +<strong>Quantifiers:</strong> + <strong><code>?</code></strong> 0 or 1 of the preceding text + <strong><code>*</code></strong> 0 or N of the preceding text (N > 0) + <strong><code>+</code></strong> 1 or N of the preceding text (N > 1) + +<strong>Grouping:</strong> + <strong><code>(</code></strong>text<strong><code>)</code></strong> Grouping of text + (either to set the borders of an alternative or + for making backreferences where the <strong>N</strong>th group can + be used on the RHS of a RewriteRule with <code>$</code><strong>N</strong>) + +<strong>Anchors:</strong> + <strong><code>^</code></strong> Start of line anchor + <strong><code>$</code></strong> End of line anchor + +<strong>Escaping:</strong> + <strong><code>\</code></strong>char escape that particular char + (for instance to specify the chars "<code>.[]()</code>" <em>etc.</em>) +</pre> + </td> + </tr> + </table> + + <p>For more information about regular expressions either have + a look at your local regex(3) manpage or its + <code>src/regex/regex.3</code> copy in the Apache 1.3 + distribution. If you are interested in more detailed + information about regular expressions and their variants + (POSIX regex, Perl regex, <em>etc.</em>) have a look at the + following dedicated book on this topic:</p> + + <blockquote> + <em>Mastering Regular Expressions</em><br /> + Jeffrey E.F. Friedl<br /> + Nutshell Handbook Series<br /> + O'Reilly & Associates, Inc. 1997<br /> + ISBN 1-56592-257-3<br /> + </blockquote> + + <p>Additionally in mod_rewrite the NOT character + ('<code>!</code>') is a possible pattern prefix. This gives + you the ability to negate a pattern; to say, for instance: + ``<em>if the current URL does <strong>NOT</strong> match this + pattern</em>''. This can be used for exceptional cases, where + it is easier to match the negative pattern, or as a last + default rule.</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Notice:</strong> When using the NOT character + to negate a pattern you cannot have grouped wildcard + parts in the pattern. This is impossible because when the + pattern does NOT match, there are no contents for the + groups. In consequence, if negated patterns are used, you + cannot use <code>$N</code> in the substitution + string!</td> + </tr> + </table> + + <p><a id="rhs" name="rhs"><em>Substitution</em></a> of a + rewriting rule is the string which is substituted for (or + replaces) the original URL for which <em>Pattern</em> + matched. Beside plain text you can use</p> + + <ol> + <li>back-references <code>$N</code> to the RewriteRule + pattern</li> + + <li>back-references <code>%N</code> to the last matched + RewriteCond pattern</li> + + <li>server-variables as in rule condition test-strings + (<code>%{VARNAME}</code>)</li> + + <li><a href="#mapfunc">mapping-function</a> calls + (<code>${mapname:key|default}</code>)</li> + </ol> + Back-references are <code>$</code><strong>N</strong> + (<strong>N</strong>=0..9) identifiers which will be replaced + by the contents of the <strong>N</strong>th group of the + matched <em>Pattern</em>. The server-variables are the same + as for the <em>TestString</em> of a <code>RewriteCond</code> + directive. The mapping-functions come from the + <code>RewriteMap</code> directive and are explained there. + These three types of variables are expanded in the order of + the above list. + + <p>As already mentioned above, all the rewriting rules are + applied to the <em>Substitution</em> (in the order of + definition in the config file). The URL is <strong>completely + replaced</strong> by the <em>Substitution</em> and the + rewriting process goes on until there are no more rules + unless explicitly terminated by a + <code><strong>L</strong></code> flag - see below.</p> + + <p>There is a special substitution string named + '<code>-</code>' which means: <strong>NO + substitution</strong>! Sounds silly? No, it is useful to + provide rewriting rules which <strong>only</strong> match + some URLs but do no substitution, <em>e.g.</em>, in + conjunction with the <strong>C</strong> (chain) flag to be + able to have more than one pattern to be applied before a + substitution occurs.</p> + + <p>One more note: You can even create URLs in the + substitution string containing a query string part. Just use + a question mark inside the substitution string to indicate + that the following stuff should be re-injected into the + QUERY_STRING. When you want to erase an existing query + string, end the substitution string with just the question + mark.</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Note</strong>: There is a special feature: + When you prefix a substitution field with + <code>http://</code><em>thishost</em>[<em>:thisport</em>] + then <strong>mod_rewrite</strong> automatically strips it + out. This auto-reduction on implicit external redirect + URLs is a useful and important feature when used in + combination with a mapping-function which generates the + hostname part. Have a look at the first example in the + example section below to understand this.</td> + </tr> + </table> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Remember:</strong> An unconditional external + redirect to your own server will not work with the prefix + <code>http://thishost</code> because of this feature. To + achieve such a self-redirect, you have to use the + <strong>R</strong>-flag (see below).</td> + </tr> + </table> + + <p>Additionally you can set special flags for + <em>Substitution</em> by appending</p> + + <blockquote> + <strong><code>[</code><em>flags</em><code>]</code></strong> + </blockquote> + as the third argument to the <code>RewriteRule</code> + directive. <em>Flags</em> is a comma-separated list of the + following flags: + + <ul> + <li> + '<strong><code>redirect|R</code> + [=<em>code</em>]</strong>' (force <a id="redirect" + name="redirect"><strong>r</strong>edirect</a>)<br /> + Prefix <em>Substitution</em> with + <code>http://thishost[:thisport]/</code> (which makes the + new URL a URI) to force a external redirection. If no + <em>code</em> is given a HTTP response of 302 (MOVED + TEMPORARILY) is used. If you want to use other response + codes in the range 300-400 just specify them as a number + or use one of the following symbolic names: + <code>temp</code> (default), <code>permanent</code>, + <code>seeother</code>. Use it for rules which should + canonicalize the URL and give it back to the client, + <em>e.g.</em>, translate ``<code>/~</code>'' into + ``<code>/u/</code>'' or always append a slash to + <code>/u/</code><em>user</em>, etc.<br /> + + + <p><strong>Note:</strong> When you use this flag, make + sure that the substitution field is a valid URL! If not, + you are redirecting to an invalid location! And remember + that this flag itself only prefixes the URL with + <code>http://thishost[:thisport]/</code>, rewriting + continues. Usually you also want to stop and do the + redirection immediately. To stop the rewriting you also + have to provide the 'L' flag.</p> + </li> + + <li>'<strong><code>forbidden|F</code></strong>' (force URL + to be <strong>f</strong>orbidden)<br /> + This forces the current URL to be forbidden, + <em>i.e.</em>, it immediately sends back a HTTP response of + 403 (FORBIDDEN). Use this flag in conjunction with + appropriate RewriteConds to conditionally block some + URLs.</li> + + <li>'<strong><code>gone|G</code></strong>' (force URL to be + <strong>g</strong>one)<br /> + This forces the current URL to be gone, <em>i.e.</em>, it + immediately sends back a HTTP response of 410 (GONE). Use + this flag to mark pages which no longer exist as gone.</li> + + <li> + '<strong><code>proxy|P</code></strong>' (force + <strong>p</strong>roxy)<br /> + This flag forces the substitution part to be internally + forced as a proxy request and immediately (<em>i.e.</em>, + rewriting rule processing stops here) put through the <a + href="mod_proxy.html">proxy module</a>. You have to make + sure that the substitution string is a valid URI + (<em>e.g.</em>, typically starting with + <code>http://</code><em>hostname</em>) which can be + handled by the Apache proxy module. If not you get an + error from the proxy module. Use this flag to achieve a + more powerful implementation of the <a + href="mod_proxy.html#proxypass">ProxyPass</a> directive, + to map some remote stuff into the namespace of the local + server. + + <p>Notice: To use this functionality make sure you have + the proxy module compiled into your Apache server + program. If you don't know please check whether + <code>mod_proxy.c</code> is part of the ``<code>httpd + -l</code>'' output. If yes, this functionality is + available to mod_rewrite. If not, then you first have to + rebuild the ``<code>httpd</code>'' program with mod_proxy + enabled.</p> + </li> + + <li>'<strong><code>last|L</code></strong>' + (<strong>l</strong>ast rule)<br /> + Stop the rewriting process here and don't apply any more + rewriting rules. This corresponds to the Perl + <code>last</code> command or the <code>break</code> command + from the C language. Use this flag to prevent the currently + rewritten URL from being rewritten further by following + rules. For example, use it to rewrite the root-path URL + ('<code>/</code>') to a real one, <em>e.g.</em>, + '<code>/e/www/</code>'.</li> + + <li>'<strong><code>next|N</code></strong>' + (<strong>n</strong>ext round)<br /> + Re-run the rewriting process (starting again with the + first rewriting rule). Here the URL to match is again not + the original URL but the URL from the last rewriting rule. + This corresponds to the Perl <code>next</code> command or + the <code>continue</code> command from the C language. Use + this flag to restart the rewriting process, <em>i.e.</em>, + to immediately go to the top of the loop.<br /> + <strong>But be careful not to create an infinite + loop!</strong></li> + + <li>'<strong><code>chain|C</code></strong>' + (<strong>c</strong>hained with next rule)<br /> + This flag chains the current rule with the next rule + (which itself can be chained with the following rule, + <em>etc.</em>). This has the following effect: if a rule + matches, then processing continues as usual, <em>i.e.</em>, + the flag has no effect. If the rule does + <strong>not</strong> match, then all following chained + rules are skipped. For instance, use it to remove the + ``<code>.www</code>'' part inside a per-directory rule set + when you let an external redirect happen (where the + ``<code>.www</code>'' part should not to occur!).</li> + + <li> + '<strong><code>type|T</code></strong>=<em>MIME-type</em>' + (force MIME <strong>t</strong>ype)<br /> + Force the MIME-type of the target file to be + <em>MIME-type</em>. For instance, this can be used to + simulate the <code>mod_alias</code> directive + <code>ScriptAlias</code> which internally forces all files + inside the mapped directory to have a MIME type of + ``<code>application/x-httpd-cgi</code>''.</li> + + <li> + '<strong><code>nosubreq|NS</code></strong>' (used only if + <strong>n</strong>o internal + <strong>s</strong>ub-request)<br /> + This flag forces the rewriting engine to skip a + rewriting rule if the current request is an internal + sub-request. For instance, sub-requests occur internally + in Apache when <code>mod_include</code> tries to find out + information about possible directory default files + (<code>index.xxx</code>). On sub-requests it is not + always useful and even sometimes causes a failure to if + the complete set of rules are applied. Use this flag to + exclude some rules.<br /> + + + <p>Use the following rule for your decision: whenever you + prefix some URLs with CGI-scripts to force them to be + processed by the CGI-script, the chance is high that you + will run into problems (or even overhead) on + sub-requests. In these cases, use this flag.</p> + </li> + + <li>'<strong><code>nocase|NC</code></strong>' + (<strong>n</strong>o <strong>c</strong>ase)<br /> + This makes the <em>Pattern</em> case-insensitive, + <em>i.e.</em>, there is no difference between 'A-Z' and + 'a-z' when <em>Pattern</em> is matched against the current + URL.</li> + + <li>'<strong><code>qsappend|QSA</code></strong>' + (<strong>q</strong>uery <strong>s</strong>tring + <strong>a</strong>ppend)<br /> + This flag forces the rewriting engine to append a query + string part in the substitution string to the existing one + instead of replacing it. Use this when you want to add more + data to the query string via a rewrite rule.</li> + + <li> + '<strong><code>noescape|NE</code></strong>' + (<strong>n</strong>o URI <strong>e</strong>scaping of + output)<br /> + This flag keeps mod_rewrite from applying the usual URI + escaping rules to the result of a rewrite. Ordinarily, + special characters (such as '%', '$', ';', and so on) + will be escaped into their hexcode equivalents ('%25', + '%24', and '%3B', respectively); this flag prevents this + from being done. This allows percent symbols to appear in + the output, as in +<pre> + RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE] + +</pre> + which would turn '<code>/foo/zed</code>' into a safe + request for '<code>/bar?arg=P1=zed</code>'. + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Notice:</strong> The + <code>noescape</code> flag is only available with + Apache 1.3.20 and later versions.</td> + </tr> + </table> + </li> + + <li> + '<strong><code>passthrough|PT</code></strong>' + (<strong>p</strong>ass <strong>t</strong>hrough to next + handler)<br /> + This flag forces the rewriting engine to set the + <code>uri</code> field of the internal + <code>request_rec</code> structure to the value of the + <code>filename</code> field. This flag is just a hack to + be able to post-process the output of + <code>RewriteRule</code> directives by + <code>Alias</code>, <code>ScriptAlias</code>, + <code>Redirect</code>, <em>etc.</em> directives from + other URI-to-filename translators. A trivial example to + show the semantics: If you want to rewrite + <code>/abc</code> to <code>/def</code> via the rewriting + engine of <code>mod_rewrite</code> and then + <code>/def</code> to <code>/ghi</code> with + <code>mod_alias</code>: +<pre> + RewriteRule ^/abc(.*) /def$1 [PT] + Alias /def /ghi + +</pre> + If you omit the <code>PT</code> flag then + <code>mod_rewrite</code> will do its job fine, + <em>i.e.</em>, it rewrites <code>uri=/abc/...</code> to + <code>filename=/def/...</code> as a full API-compliant + URI-to-filename translator should do. Then + <code>mod_alias</code> comes and tries to do a + URI-to-filename transition which will not work. + + <p>Note: <strong>You have to use this flag if you want to + intermix directives of different modules which contain + URL-to-filename translators</strong>. The typical example + is the use of <code>mod_alias</code> and + <code>mod_rewrite</code>..</p> + </li> + + <li>'<strong><code>skip|S</code></strong>=<em>num</em>' + (<strong>s</strong>kip next rule(s))<br /> + This flag forces the rewriting engine to skip the next + <em>num</em> rules in sequence when the current rule + matches. Use this to make pseudo if-then-else constructs: + The last rule of the then-clause becomes + <code>skip=N</code> where N is the number of rules in the + else-clause. (This is <strong>not</strong> the same as the + 'chain|C' flag!)</li> + + <li> + '<strong><code>env|E=</code></strong><em>VAR</em>:<em>VAL</em>' + (set <strong>e</strong>nvironment variable)<br /> + This forces an environment variable named <em>VAR</em> to + be set to the value <em>VAL</em>, where <em>VAL</em> can + contain regexp backreferences <code>$N</code> and + <code>%N</code> which will be expanded. You can use this + flag more than once to set more than one variable. The + variables can be later dereferenced in many situations, but + usually from within XSSI (via <code><!--#echo + var="VAR"--></code>) or CGI (<em>e.g.</em> + <code>$ENV{'VAR'}</code>). Additionally you can dereference + it in a following RewriteCond pattern via + <code>%{ENV:VAR}</code>. Use this to strip but remember + information from URLs.</li> + </ul> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td> + <strong>Note:</strong> Never forget that + <em>Pattern</em> is applied to a complete URL in + per-server configuration files. <strong>But in + per-directory configuration files, the per-directory + prefix (which always is the same for a specific + directory!) is automatically <em>removed</em> for the + pattern matching and automatically <em>added</em> after + the substitution has been done.</strong> This feature + is essential for many sorts of rewriting, because + without this prefix stripping you have to match the + parent directory which is not always possible. + + <p>There is one exception: If a substitution string + starts with ``<code>http://</code>'' then the directory + prefix will <strong>not</strong> be added and an + external redirect or proxy throughput (if flag + <strong>P</strong> is used!) is forced!</p> + </td> + </tr> + </table> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>Note:</strong> To enable the rewriting engine + for per-directory configuration files you need to set + ``<code>RewriteEngine On</code>'' in these files + <strong>and</strong> ``<code>Options + FollowSymLinks</code>'' must be enabled. If your + administrator has disabled override of + <code>FollowSymLinks</code> for a user's directory, then + you cannot use the rewriting engine. This restriction is + needed for security reasons.</td> + </tr> + </table> + + <p>Here are all possible substitution combinations and their + meanings:</p> + + <p><strong>Inside per-server configuration + (<code>httpd.conf</code>)<br /> + for request ``<code>GET + /somepath/pathinfo</code>'':</strong><br /> + </p> + + <table bgcolor="#F0F0F0" cellspacing="0" cellpadding="5"> + <tr> + <td> +<pre> +<strong>Given Rule</strong> <strong>Resulting Substitution</strong> +---------------------------------------------- ---------------------------------- +^/somepath(.*) otherpath$1 not supported, because invalid! + +^/somepath(.*) otherpath$1 [R] not supported, because invalid! + +^/somepath(.*) otherpath$1 [P] not supported, because invalid! +---------------------------------------------- ---------------------------------- +^/somepath(.*) /otherpath$1 /otherpath/pathinfo + +^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo + via external redirection + +^/somepath(.*) /otherpath$1 [P] not supported, because silly! +---------------------------------------------- ---------------------------------- +^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo + +^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo + via external redirection + +^/somepath(.*) http://thishost/otherpath$1 [P] not supported, because silly! +---------------------------------------------- ---------------------------------- +^/somepath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo + via external redirection + +^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo + via external redirection + (the [R] flag is redundant) + +^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo + via internal proxy +</pre> + </td> + </tr> + </table> + + <p><strong>Inside per-directory configuration for + <code>/somepath</code><br /> + (<em>i.e.</em>, file <code>.htaccess</code> in dir + <code>/physical/path/to/somepath</code> containing + <code>RewriteBase /somepath</code>)<br /> + for request ``<code>GET + /somepath/localpath/pathinfo</code>'':</strong><br /> + </p> + + <table bgcolor="#F0F0F0" cellspacing="0" cellpadding="5"> + <tr> + <td> +<pre> +<strong>Given Rule</strong> <strong>Resulting Substitution</strong> +---------------------------------------------- ---------------------------------- +^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo + +^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo + via external redirection + +^localpath(.*) otherpath$1 [P] not supported, because silly! +---------------------------------------------- ---------------------------------- +^localpath(.*) /otherpath$1 /otherpath/pathinfo + +^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo + via external redirection + +^localpath(.*) /otherpath$1 [P] not supported, because silly! +---------------------------------------------- ---------------------------------- +^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo + +^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo + via external redirection + +^localpath(.*) http://thishost/otherpath$1 [P] not supported, because silly! +---------------------------------------------- ---------------------------------- +^localpath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo + via external redirection + +^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo + via external redirection + (the [R] flag is redundant) + +^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo + via internal proxy +</pre> + </td> + </tr> + </table> + + <p><strong>Example:</strong></p> + + <blockquote> + We want to rewrite URLs of the form + + <blockquote> + <code>/</code> <em>Language</em> <code>/~</code> + <em>Realname</em> <code>/.../</code> <em>File</em> + </blockquote> + into + + <blockquote> + <code>/u/</code> <em>Username</em> <code>/.../</code> + <em>File</em> <code>.</code> <em>Language</em> + </blockquote> + + <p>We take the rewrite mapfile from above and save it under + <code>/path/to/file/map.txt</code>. Then we only have to + add the following lines to the Apache server configuration + file:</p> + + <blockquote> +<pre> +RewriteLog /path/to/file/rewrite.log +RewriteMap real-to-user txt:/path/to/file/map.txt +RewriteRule ^/([^/]+)/~([^/]+)/(.*)$ /u/${real-to-user:$2|nobody}/$3.$1 +</pre> + </blockquote> + </blockquote> + <hr noshade="noshade" size="1" /> + + <center> + <h1><a id="Miscelleneous" + name="Miscelleneous">Miscellaneous</a></h1> + </center> + <hr noshade="noshade" size="1" /> + + <h2><a id="EnvVar" name="EnvVar">Environment + Variables</a></h2> + This module keeps track of two additional (non-standard) + CGI/SSI environment variables named <code>SCRIPT_URL</code> + and <code>SCRIPT_URI</code>. These contain the + <em>logical</em> Web-view to the current resource, while the + standard CGI/SSI variables <code>SCRIPT_NAME</code> and + <code>SCRIPT_FILENAME</code> contain the <em>physical</em> + System-view. + + <p>Notice: These variables hold the URI/URL <em>as they were + initially requested</em>, <em>i.e.</em>, <em>before</em> any + rewriting. This is important because the rewriting process is + primarily used to rewrite logical URLs to physical + pathnames.</p> + + <p><strong>Example:</strong></p> + + <blockquote> +<pre> +SCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html +SCRIPT_FILENAME=/u/rse/.www/index.html +SCRIPT_URL=/u/rse/ +SCRIPT_URI=http://en1.engelschall.com/u/rse/ +</pre> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h2><a id="Solutions" name="Solutions">Practical + Solutions</a></h2> + We also have an <a href="../misc/rewriteguide.html">URL + Rewriting Guide</a> available, which provides a collection of + practical solutions for URL-based problems. There you can + find real-life rulesets and additional information about + mod_rewrite. + </blockquote> + <hr /> + + <h3 align="CENTER">Apache HTTP Server Version 1.3</h3> + <a href="./"><img src="../images/index.gif" alt="Index" /></a> + <a href="../"><img src="../images/home.gif" alt="Home" /></a> + + <!-- page indentation --> + <!--/%hypertext --> + </body> +</html> + + + diff --git a/usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.ja.jis b/usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.ja.jis new file mode 100644 index 00000000000..e9c4fc5a30f --- /dev/null +++ b/usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.ja.jis @@ -0,0 +1,2102 @@ +<?xml version="1.0" encoding="iso-2022-jp"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<!--%hypertext --> +<!-- mod_rewrite.html --> +<!-- Documentation for the mod_rewrite Apache module --> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja"> + <head> + + <title>Apache module mod_rewrite</title> + </head> + <!-- English revision: 1.64 --> + <!-- Background white, links blue (unvisited), navy (visited), red (active) --> + + <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" + vlink="#000080" alink="#FF0000"> + <blockquote> + <!-- page indentation --> + <div align="CENTER"> + <img src="../images/sub.gif" alt="[APACHE DOCUMENTATION]" /> + + <h3>Apache HTTP Server Version 1.3</h3> + </div> + + <br /> + + <h1 align="center">mod_rewrite $B%b%8%e!<%k(B<br /> + URL $B=q$-49$(%(%s%8%s(B</h1> + + <p>$B$3$N%b%8%e!<%k$O!"MW5a$5$l$?(B URL + $B$r%j%"%k%?%$%`$G=q$-49$($k$?$a$N!"(B + $B%k!<%k%Y!<%9$N=q$-49$(%(%s%8%s$rDs6!$7$^$9!#(B + </p> + + <p><a href="module-dict.html#Status" + rel="Help"><strong>$B%9%F!<%?%9(B:</strong></a> Extension<br /> + <a href="module-dict.html#SourceFile" + rel="Help"><strong>$B%=!<%9%U%!%$%k(B:</strong></a> + mod_rewrite.c<br /> + <a href="module-dict.html#ModuleIdentifier" + rel="Help"><strong>$B%b%8%e!<%k<1JL;R(B:</strong></a> + rewrite_module<br /> + <a href="module-dict.html#Compatibility" + rel="Help"><strong>$B8_49@-(B:</strong></a> Apache 1.2 $B0J9_$G;HMQ2DG=(B</p> + <hr noshade="noshade" size="1" /> + <br /> + + <h2>$B35MW(B</h2> + + <blockquote> + <blockquote> + <blockquote> + <em>`` mod_rewrite $B$N$9$P$i$7$$$H$3$m$O!"(B + Sendmail $B$N$h$&$J@_Dj@-$H=@Fp@-$rM?$($F$/$l$k$H$3$m$@$m$&!#(B + $B$^$?!"(Bmod_rewrite $B$N$h$/$J$$$H$3$m$O!"(B + Sendmail $B$N$h$&$J@_Dj@-$H=@Fp@-$rM?$($F$/$l$k$H$3$m$@$m$&!#(B''</em> + + <div align="right"> + -- Brian Behlendorf<br /> + Apache Group + </div> + </blockquote> + </blockquote> + </blockquote> + + <blockquote> + <blockquote> + <blockquote> + <em>`` $BKDBg$J@_DjNc$d%I%-%e%a%s%H$,$"$k$K$b$+$+$o$i$:!"(B + mod_rewrite $B$O9uKb=Q$G$"$k!#$+$J$j%$%1$F$k$C$]$$9uKb=Q$@$,!"(B + $B$d$C$Q$j9uKb=Q$G$"$k!#(B''</em> + + <div align="right"> + -- Brian Moore<br /> + bem@news.cmc.net + </div> + </blockquote> + </blockquote> + </blockquote> + URL $B$rA`:n$9$k$?$a$N%9%$%9@=$N%"!<%_!<%J%$%U!"(Bmod_rewrite + $B$X$h$&$3$=(B! + + <p>$B$3$N%b%8%e!<%k$O!"(B($B@55,I=8=%Q!<%5$K4p$E$/(B) + $B%k!<%k%Y!<%9$N=q$-49$(%(%s%8%s$r;H$$!"MW5a$5$l$?(B URL + $B$rE,59=q$-49$($^$9!#%5%]!<%H$9$k%k!<%k$N?t!"(B + $B$*$h$S3F%k!<%k$rE,MQ$9$k:]$N%k!<%k>r7o$N?t$K@)8B$O$J$/!"(B + $BK\Ev$K=@Fp$G$+$D6/NO$J(B URL $BA`:n%a%+%K%:%`$rDs6!$7$^$9!#$3$N(B URL + $BA`:n$K@hN)$A!"<!$N$h$&$K$$$m$$$m$JI>2A$r9T$&$3$H$,$G$-$^$9!#(B + $BNc$($P%5!<%PJQ?t!"4D6-JQ?t!"(BHTTP $B%X%C%@!"%?%$%`%9%?%s%W!"(B + $B$5$i$K30It%G!<%?%Y!<%9$N8!:w7k2L$^$G$rI>2A$NBP>]$H$7$F!"(B + $B3F<o$N%U%)!<%^%C%H$r;H$C$?:YN3EY$N(B URL $B%^%C%A%s%0$r<B8=$G$-$^$9!#(B + </p> + + <p>$B$3$N%b%8%e!<%k$O!"%5!<%PC10L$N%3%s%F%-%9%H(B + (<code>httpd.conf</code>) $B$*$h$S%G%#%l%/%H%jC10L$N%3%s%F%-%9%H(B + (<code>.htaccess</code>) $B$K$*$$$F(B (PATH-INFO $BItJ,$r4^$`(B) $B%U%k(B + URL $B$KBP$9$kA`:n$r9T$$$^$9$,!"(B + $B$5$i$K7k2L$H$7$F%/%(%j!<J8;zNsItJ,$r@8@.$9$k$3$H$b$G$-$^$9!#(B + $B=PNO$5$l$?7k2L$rFbIt$N%5%V%W%m%;%9$d30It%j%/%(%9%H$N%j%@%$%l%/%7%g%s!"(B + $B$5$i$K$OFbIt$N%W%m%-%7=hM}%k!<%A%s$KEO$9$3$H$b$G$-$^$9!#(B + </p> + + <p>$B$?$@!"$3$l$i$9$Y$F$N5!G=$d=@Fp@-$,!"(B + $B7gE@$G$"$kJ#;($5$N85$K$b$J$C$F$$$^$9!#$J$N$G!"$3$N%b%8%e!<%k(B + $BA4BN$r0lF|DxEY$G3P$($h$&$J$I$H$O;W$o$J$$$[$&$,$$$$$G$7$g$&!#(B + </p> + + <p>$B$3$N%b%8%e!<%k$O(B 1996 $BG/$N(B 4 $B7n$K(B</p> + + <blockquote> + <a href="http://www.engelschall.com/"><code>Ralf S. + Engelschall</code></a><br /> + <a + href="mailto:rse@engelschall.com"><code>rse@engelschall.com</code></a><br /> + <a + href="http://www.engelschall.com/"><code>www.engelschall.com</code></a> + </blockquote> + + <p>$B$i$K$h$j9M0F$5$l$F%*%j%8%J%k$,=q$+$l!"(B<br /> + 1997 $BG/$N(B 7 $B7n$K!"(BThe Apache Group + $B$KBP$7$FFH@jE*$KB#Dh$5$l$^$7$?!#(B</p> + <hr noshade="noshade" size="1" /> + + <h2>$BL\<!(B</h2> + + <p><strong>$BFbIt=hM}(B</strong></p> + + <ul> + <li><a href="#InternalAPI">API $B%U%'!<%:(B</a></li> + + <li><a href="#InternalRuleset">$B%k!<%k%;%C%H=hM}(B</a></li> + + <li><a href="#InternalBackRefs">$B@55,I=8=$N8eJ};2>H$,2DG=(B</a></li> + </ul> + + <p><strong>$B@_Dj%G%#%l%/%F%#%V(B</strong></p> + + <ul> + <li><a href="#RewriteEngine">RewriteEngine</a></li> + + <li><a href="#RewriteOptions">RewriteOptions</a></li> + + <li><a href="#RewriteLog">RewriteLog</a></li> + + <li><a href="#RewriteLogLevel">RewriteLogLevel</a></li> + + <li><a href="#RewriteLock">RewriteLock</a></li> + + <li><a href="#RewriteMap">RewriteMap</a></li> + + <li><a href="#RewriteBase">RewriteBase</a></li> + + <li><a href="#RewriteCond">RewriteCond</a></li> + + <li><a href="#RewriteRule">RewriteRule</a></li> + </ul> + <strong>$B$=$NB>(B</strong> + + <ul> + <li><a href="#EnvVar">$B4D6-JQ?t(B</a></li> + + <li><a href="#Solutions">$B<BNc(B</a></li> + </ul> + <hr noshade="noshade" size="1" /> + + <center> + <h1><a id="Internal" name="Internal">$BFbIt=hM}(B</a></h1> + </center> + <hr noshade="noshade" size="1" /> + + <p>$B$3$N%b%8%e!<%k$NFbIt=hM}$O$H$F$bJ#;($G$9$,!"(B + $B$"$j$,$A$J%_%9$rHr$1!"$^$?A45!G=$r3hMQ$G$-$k$h$&$K!"(B + $BJ?6QE*%f!<%6$KBP$7$F$b0lEY$O@bL@$7$F$*$/I,MW$,$"$j$^$9!#(B + </p> + + <h2><a id="InternalAPI" name="InternalAPI">API $B%U%'!<%:(B</a></h2> + + <p>$B$^$:$O!"(BApache $B$,(B HTTP $B%j%/%(%9%H$r=hM}$9$k:]$K!"(B + $B$3$N%b%8%e!<%k$,$3$N%U%'!<%:$G9T$&$3$H$rM}2r$7$F$*$+$J$1$l$P$J$j$^$;$s!#(B + Apache API $B$G$O!"$3$l$i$N3F%U%'!<%:$KBP$9$k%U%C%/$,Ds6!$5$l$F$$$^$9!#(B + mod_rewrite $B$O0J2<$NFs$D$N%U%C%/$r;H$$$^$9(B: HTTP + $B%j%/%(%9%H$,FI$^$l$?8e$G$+$D$9$Y$F$NG'>Z$,3+;O$5$l$kA0$K;H$o$l$k(B + URL-to-filename $BJQ49%U%C%/!"$=$7$F!"G'>Z%U%'!<%:$N8e$G(B + $B%G%#%l%/%H%j$4$H$N@_Dj%U%!%$%k(B (<code>.htaccess</code>) + $B$,FI$^$l$?8e!"$^$@(B content $B%O%s%I%i$,M-8z$K$J$kA0$K5/F0$5$l$k(B + Fixup $B%U%C%/$G$9!#(B + </p> + + <p>$B$=$7$F!"$"$k%j%/%(%9%H$,F~$C$FMh$F!"(BApache $B$,$3$l$KBP1~$9$k%5!<%P(B + ($B<c$7$/$O%P!<%A%c%k%5!<%P(B) $B$r7hDj$7$?8e$K!"=q$-49$(%(%s%8%s$O!"(B + $B%5!<%P$4$H$N@_Dj$r85$K!"(BURL-to-filename $B%U%'!<%:$G$9$Y$F$N(B + mod_rewrite $B%G%#%l%/%F%#%V$N=hM}$r3+;O$7$^$9!#(B + $B$=$N8eB?>/$N%9%F%C%W$r7P$F:G8e$N%G!<%?%G%#%l%/%H%j$,8+$D$+$C$?;~!"(B + $B%G%#%l%/%H%j$4$H$N(B mod_rewrite $B@_Dj%G%#%l%/%F%#%V$,(B Fixup + $B%U%'!<%:$G5/F0$5$l$^$9!#(B + $B$3$N3F!9$N%?%$%_%s%0$N4V$KFC$KL@$i$+$J0c$$$O$J$$$N$G$9$,!"$=$l$G$b(B + mod_rewrite $B$O$$$:$l$N;~$K$b3F(B URL $B$r?7$7$$(B URL + $B$^$?$O%U%!%$%kL>$K=q$-49$($^$9!#$3$l$O$3$N(B API + $B$,%G%6%$%s$5$l$?;~$KA[Dj$5$l$?;H$$J}$G$O$J$$$N$G$9$,!"(BApache 1.x + $B$K$*$$$F$O$3$l$,(B mod_rewrite $B$,F0$1$kM#0l$NJ}K!$G$7$?!#(B + $B$3$NE@$r$h$j$O$C$-$j$5$;$k$?$a$K!"0J2<$N(B 2 + $BE@$K$D$$$F3P$($F$*$$$F$/$@$5$$(B:</p> + + <ol> + <li>mod_rewrite $B$O(B URL $B$r(B URL $B$X!"(BURL $B$r%U%!%$%kL>$X!"(B + $B$5$i$K%U%!%$%kL>$r%U%!%$%kL>$X$H=q$-49$($^$9$,!"(BAPI + $B$G$O8=:_$N$H$3$m(B URL-to-filename $B%U%C%/$N$_$rDs6!$7$F$$$^$9!#(B + Apache 2.0 $B$G$O$=$l$^$G$K$O$J$+$C$?Fs$D$N%U%C%/$,DI2C$5$l!"(B + $B=hM}$,$h$jL@3N$K$J$j$^$7$?!#(B + $B$7$+$7$3$NE@$G$O%f!<%6$K$H$C$F$NITMx1W$O$J$/!"(B + $BC1$K3P$($F$*$/$Y$-;v<B$H$7$F$O(B: Apache $B$O(B URL-to-filename + $B%U%C%/$K$*$$$F(B API $B$,0U?^$9$k0J>e$N$3$H$r9T$$$^$9!#(B</li> + + <li>mod_rewrite $B$G$O!"?.$8$i$l$J$$$3$H$K!"(BURL + $B$,%U%!%$%kL>$KJQ49$5$l$F$+$i$:$C$H8e$KC)$jCe$/$H$3$m$K$"$k!"(B + $B%G%#%l%/%H%j$4$H$N%3%s%F%-%9%H(B<em>$B$9$J$o$A(B</em> + <code>.htaccess</code> $B%U%!%$%k$NCf$G(B URL + $BA`:n$r9T$($k$h$&$K$J$C$F$$$9!#(B<code>.htaccess</code> + $B%U%!%$%k$O%U%!%$%k%7%9%F%`Cf$K$"$k$?$a$K(B + $B=hM}$NN.$l$O$9$G$K$3$NCJ3,$^$GE~C#$7$F$$$k$N$G!"(B + $B$3$N$h$&$K$J$C$F$$$k$N$G$9!#$D$^$j$3$N;~E@$G(B API + $B%U%'!<%:$K=>$($P!"$I$N(B URL + $B$rA`:n$9$k$K$b4{$KCY$-$K<:$7$F$$$k$N$G$9!#(B + $B$3$N7\$HMqLdBj$rBG3+$9$k$?$a!"(Bmod_rewrite + $B$G$O$A$g$C$H$7$?%H%j%C%/$r;H$C$F$$$^$9(B: + $B%G%#%l%/%H%j$4$H$N%3%s%F%-%9%H$G(B URL / $B%U%!%$%kL>$NA`:n$r9T$&:]!"(B + mod_rewrite $B$O$^$:%U%!%$%kL>$rBP1~$9$k(B URL $B$KLa$7(B + ($B$3$l$ODL>oIT2DG=$G$9$,!"$3$l$r2DG=$K$9$k%H%j%C%/$K$D$$$F$O(B + <code>RewriteBase</code> $B$r8+$F$/$@$5$$(B) $B!"$=$N?7$7$$(B URL + $B$GFbItE*$K?7$7$$%5%V%j%/%(%9%H$r@8@.$7$F$$$k$N$G$9!#$3$l$G(B + API $B%U%'!<%:=hM}$,:FEY5/F0$5$l$^$9!#(B + + <p>$B$3$N$h$&$K!"(Bmod_rewrite $B$OJ#;($J%9%F%C%W$r(B + $B%f!<%6$KBP$7$FA4HL$KF)2aE*$K$7$h$&$H$,$s$P$C$F$$$^$9$,!"(B + $B$H$j$"$($:0J2<$N$3$H$O3P$($F$*$/$Y$-$G$7$g$&(B: + $B%5!<%P$4$H$N%3%s%F%-%9%H$K$*$1$k(B URL + $BA`:n$OHs>o$K9bB.$G$+$D8zN($,NI$$$N$KBP$7!"(B + $B%G%#%l%/%H%j$4$H$N=q$-49$($O!"(B + $B$3$N7\$HMq$NLdBj$N$?$aCY$$>e$KDc8zN($G$9!#$7$+$7$3$l$O!"(B + mod_rewrite $B$,$4$/J?6QE*$J%f!<%6$KDs6!$G$-$k!"(B + ($B%m!<%+%k$K@)8B$5$l$?(B) URL $BA`:n$N$?$a$NM#0l$NJ}K!$J$N$G$9!#(B + </p> + </li> + </ol> + + <p>$B$3$l$iFs$D$NE@$rK:$l$J$$$G$/$@$5$$(B!</p> + + <h2><a id="InternalRuleset" + name="InternalRuleset">$B%k!<%k%;%C%H=hM}(B</a></h2> + $B$3$l$iFs$D$N(B API $B%U%'!<%:$G(B mod_rewrite $B$,5/F0$5$l$k$H!"(B + mod_rewrite $B$O$^$:<+J,<+?H$N@_DjMQ9=B$BN(B + ($B$3$l$O5/F0;~$N%5!<%P$4$H$N%3%s%F%-%9%H$+!"(BApache + $B%+!<%M%k$,%G%#%l%/%H%j4V$rC5:w$9$kESCf$N%G%#%l%/%H%j$4$H$N(B + $B%3%s%F%-%9%H$+!"$N$$$:$l$+$K$h$j@8@.$5$l$k(B) + $B$h$j9=@.$5$l$?%k!<%k%;%C%H$rFI$_9~$_$^$9!#$=$7$F$=$NCf$KF~$C$F$$$k(B + $B%k!<%k%;%C%H(B ($B>r7o$rH<$&0l$D0J>e$N%k!<%k$N=8$^$j(B)$B$H$H$b$K(B URL + $B=q$-49$(%(%s%8%s$,3+;O$5$l$^$9!#(BURL $B=q$-49$(%(%s%8%s<+BN$O!"(B + $BAPJ}$N@_Dj%3%s%F%-%9%H$GA4$/F1$8$h$&$KF0:n$7$^$9!#(B + $B:G=*7k2L$N=hM}$,0[$J$k$@$1$G$9!#(B + + <p>$B%k!<%k%;%C%HCf$N%k!<%k$N=q$-=g$O=EMW$G$9!#(B + $B$3$l$O!"=q$-49$(%(%s%8%s$O$=$l$i$rFCJL$J(B + ($B$+$D!"$"$^$jJ,$+$j$d$9$$$H$O8@$($J$$(B) $B=g=x$G=hM}$9$k$+$i$G$9!#(B + $B%k!<%k$O0J2<$N$h$&$K=hM}$5$l$^$9(B: $B=q$-49$(%(%s%8%s$O%k!<%k(B + (<code>RewriteRule</code>$B%G%#%l%/%F%#%V(B) $B$r0l$D$:$D$J$a$J$,$i(B + $B%k!<%k%;%C%HCf$r%k!<%W$7$^$9$,!"$"$k%k!<%k$,%^%C%A$7$?$i!"(B + $B$=$l$KBP1~$9$k>r7o(B (<code>RewriteCond</code>$B%G%#%l%/%F%#%V(B) + $B$,$"$k4V$=$NCf$r%k!<%W$7$^$9!#(B + $BNr;KE*$JM}M3$K$h$j$^$:>r7o$,M?$($i$l$k$?$a!"(B + $B@)8f%U%m!<$,$A$g$C$H$/$I$/$J$C$F$$$^$9!#>\:Y$O?^(B 1 + $B$r$4Mw$/$@$5$$!#(B</p> + + <div align="center"> + <table cellspacing="0" cellpadding="2" border="0"> + <tr> + <td bgcolor="#CCCCCC"><img + src="../images/mod_rewrite_fig1.gif" width="428" + height="385" + alt="[$BI=<($9$k$K$O%0%i%U%#%C%/5!G=$,I,MW$G$9(B]" /></td> + </tr> + + <tr> + <td align="center"><strong>$B?^(B 1:</strong> + $B=q$-49$(%k!<%k%;%C%H$K$*$1$k@)8f%U%m!<(B</td> + </tr> + </table> + </div> + + <p>$B$b$&$*J,$+$j$N$h$&$K!"$^$:(B URL $B$r3F%k!<%k$N(B <em>Pattern</em> + $B$KBP$7$F%^%C%A%s%0$7$^$9!#%^%C%A$7$J$$>l9g!"(Bmod_rewrite + $B$O$9$0$K$3$N%k!<%k$N=hM}$rCf;_$7$F<!$N%k!<%k$r8+$K9T$-$^$9!#(B + <em>Pattern</em> $B$K%^%C%A$9$k$H!"(Bmod_rewrite + $B$O$=$l$KBP1~$9$k>r7o$rC5$7$^$9!#$b$72?$b$J$1$l$P!"C1$K(B URL + $B$r(B <em>Substitution</em> $BJ8;zNs$+$i:n$i$l$??7$7$$CM$KCV49$7!"(B + $B%k!<%k$N%k!<%W$rB3$1$^$9!#2?$i$+$N>r7o$,$"$l$PFbIt%k!<%W$r3+;O$7!"(B + $B$=$l$i$N>r7o$,Ns5s$5$l$F$$$k=g$K=hM}$r7+$jJV$7$^$9!#(B + $B>r7oJ8$N>l9g$O%m%8%C%/$,0[$J$j$^$9(B: $B8=:_$N(B URL + $B$KBP$7$F$O%Q%?!<%s$N%^%C%A%s%0$r9T$$$^$;$s!#$=$NBe$o$j!"(B + $B$^$:JQ?t$rE83+$7!"8eJ};2>H$r9T$$!"(B + $B8!:w%F!<%V%k$r%^%C%T%s%0$9$k(B<em>$B$J$I(B</em>$B$7$F(B<em>$B%F%9%HJ8;zNs(B</em> + $B$r@8@.$7!"$=$l$KBP$7$F(B<em>$B>r7o%Q%?!<%s(B</em>$B$H$N%^%C%A%s%0$r9T$$$^$9!#(B + $B%Q%?!<%s$K%^%C%A$7$J$$>l9g!">r7o$NAH$_9g$o$;A4BN$H$=$l$KBP1~$9$k(B + $B%k!<%k$O@.N)$7$J$$$3$H$K$J$j$^$9!#%Q%?!<%s$K%^%C%A$7$?>l9g!"(B + $B<!$N>r7o$,I>2A$5$l!"$=$l$,>r7o$N$"$k8B$j7+$jJV$5$l$^$9!#(B + $B$b$7$9$Y$F$N>r7o$K%^%C%A$9$l$P!"(BURL $B$O(B <em>Substitution</em> + $BJ8;zNs$KCV49$5$l!"=hM}$,7QB3$5$l$^$9!#(B</p> + + <h2><a id="quoting" name="quoting">$BFC<lJ8;z$N%/%&%)!<%H(B</a></h2> + + <p>Apache 1.3.20 $B$G$O!"(B<em>$B%F%9%HJ8;zNs(B</em>$B$H(B <em>Substitution</em> + $BJ8;zNs$NCf$NFC<lJ8;z$O!"$=$ND>A0$K%P%C%/%9%i%C%7%e(B ('\') + $B$rCV$/$3$H$G%(%9%1!<%W(B ($B$9$J$o$A!"$=$l$i$N;}$DFC<l$J0UL#$rBG$A>C$7$F!"(B + $BDL>o$NJ8;z$H$7$F07$&$3$H(B) $B$G$-$k$h$&$K$J$C$F$$$^$9!#(B + $BNc$($P!"(B<em>$BCV49BP>](B</em>$BJ8;zNs$NCf$G$b(B '<code>\$</code>' + $B$H$$$&J8;zNs$r;H$C$FK\Mh$N%I%k5-9f$rF~$l$k$3$H$,$G$-$k$o$1$G$9!#(B + $B$3$l$K$h$j!"(Bmod_rewrite + $B$,$=$l$r8eJ};2>H$H$7$F07$*$&$H$9$k$N$rKI$0$3$H$,$G$-$k$o$1$G$9!#(B + </p> + + <h2><a id="InternalBackRefs" + name="InternalBackRefs">$B@55,I=8=$N8eJ};2>H$r;H$&(B</a></h2> + $B$3$3$G$R$H$D3P$($F$*$$$FM_$7$$$3$H$,$"$j$^$9(B: <em>Pattern</em> + $B$NCf$d(B <em>CondPattern</em> $B$N$&$A$N$I$3$+$G3g8L$r;H$($P!"J8;zNs(B + <code>$N</code> $B$H(B <code>%N</code> + $B$G;H$($k8eJ};2>H$,FbItE*$K@8@.$5$l$^$9(B ($B8e=R(B)$B!#$3$l$i$O(B + <em>Substitution</em> + $BJ8;zNs$d(B<em>$B%F%9%HJ8;zNs(B</em>$B$r@8@.$9$k$N$K;H$($^$9!#?^(B 2 + $B$G$O!"$3$N8eJ};2>H$,E>Aw$5$l$FE83+$5$l$k>l=j$K$D$$$F2r@b$7$^$9!#(B + + <div align="center"> + <table cellspacing="0" cellpadding="2" border="0"> + <tr> + <td bgcolor="#CCCCCC"><img + src="../images/mod_rewrite_fig2.gif" width="381" + height="179" + alt="[$BI=<($9$k$K$O%0%i%U%#%C%/5!G=$,I,MW$G$9(B]" /></td> + </tr> + + <tr> + <td align="center"><strong>$B?^(B 2:</strong> + $B%k!<%k$rDL$7$?8eJ};2>H$NN.$l(B</td> + </tr> + </table> + </div> + + <p>$B$3$l$^$G$O(B mod_rewrite + $B$NFbIt=hM}$K4X$9$kC;4|=8Cf%3!<%9$G$7$?!#(B + $B$3$3$+$i$O;HMQ2DG=$J%G%#%l%/%F%#%V$K4X$9$k$3$H$,=q$+$l$F$$$^$9!#(B + $B$=$l$i$rFI$`$H$-$K$3$3$^$G$NCN<1$,LrN)$D$O$:$G$9!#(B</p> + <hr noshade="noshade" size="1" /> + + <center> + <h1><a id="Configuration" + name="Configuration">$B@_Dj%G%#%l%/%F%#%V(B</a></h1> + </center> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteEngine" + name="RewriteEngine">RewriteEngine</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>$B=q<0(B:</strong></a> RewriteEngine + on|off<br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>$B%G%U%)%k%H(B:</strong></a> <code>RewriteEngine + off</code><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>$B%3%s%F%-%9%H(B:</strong></a> $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H!"%G%#%l%/%H%j!"(B.htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>$B%*!<%P!<%i%$%I(B:</strong></a> FileInfo<br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>$B%9%F!<%?%9(B:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>$B%b%8%e!<%k(B:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>$B8_49@-(B:</strong></a> Apache + 1.2<br /> + + <p><code>RewriteEngine</code> $B%G%#%l%/%F%#%V$r;H$&$H!"(B + $B<B9T;~$N=q$-49$(%(%s%8%s$rM-8z$K$7$?$jL58z$K$7$?$j$G$-$^$9!#$3$l$,(B + <code>off</code> $B$K@_Dj$5$l$F$$$k$H!"$3$N%b%8%e!<%k$O<B9T;~$N(B + $B=hM}$r0l@Z9T$$$^$;$s!#$^$?(B <code>SCRIPT_URx</code> + $B4D6-JQ?t$N99?7$5$($b$7$J$/$J$j$^$9!#(B</p> + + <p><code>RewriteRule</code> $B$rA4It%3%a%s%H%"%&%H$7$?$j$7$J$$$G!"(B + $B$3$N%G%#%l%/%F%#%V$r;H$C$F$/$@$5$$$M!#(B</p> + + <p>$B%G%U%)%k%H$G$O!"(Brewrite $B$N@_Dj$O7Q>5$5$l$J$$$N$GCm0U$7$F$/$@$5$$!#(B + $B$D$^$j!"$3$N5!G=$r;H$$$?$$$H;W$&%P!<%A%c%k%[%9%H$4$H$K(B + <code>RewriteEngine on</code> + $B%G%#%l%/%F%#%V$r=q$+$J$1$l$P$$$1$J$$$H$$$&$3$H$G$9!#(B</p> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteOptions" + name="RewriteOptions">RewriteOptions</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>$B=q<0(B:</strong></a> RewriteOptions + <em>$B%*%W%7%g%s(B</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>$B%G%U%)%k%H(B:</strong></a> <code>RewriteOptions + MaxRedirects=10</code><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>$B%3%s%F%-%9%H(B:</strong></a> $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H!"%G%#%l%/%H%j!"(B.htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>$B%*!<%P!<%i%$%I(B:</strong></a> FileInfo<br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>$B%9%F!<%?%9(B:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>$B%b%8%e!<%k(B:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>$B8_49@-(B:</strong></a> Apache + 1.2$B!#(B<code>MaxRedirects</code> $B$O(B Apache 1.3.28 $B0J9_$G;HMQ2DG=(B<br /> + + <p><code>RewriteOptions</code> $B%G%#%l%/%F%#%V$O!"(B + $B8=:_$N%5!<%PC10L$b$7$/$O%G%#%l%/%H%jC10L$N@_Dj$G;HMQ$9$k!"(B + $BFCJL$J%*%W%7%g%s$r%;%C%H$7$^$9!#(B + <em>Option</em> $BJ8;zNs$O0J2<$N$$$:$l$+$G$9(B:</p> + + <dl> + <dt><code>inherit</code></dt> + <dd>$B$3$l$O!"8=:_$N@_DjCM$r?F$N@_DjCM$+$i6/@)E*$K7Q>5$5$;$^$9!#(B + $B$3$l$K$h$j!"2>A[%5!<%PC10L$N%3%s%F%-%9%H$K$*$$$F!"(B + $B%a%$%s%5!<%P$N%^%C%W!">r7o!"%k!<%k$,7Q>5$5$l$k$3$H$K$J$j$^$9!#(B + $B$^$?!"%G%#%l%/%H%jC10L$N%3%s%F%-%9%H$G$O!"?F%G%#%l%/%H%j$N(B + <code>.htaccess</code> + $B@_Dj$K5-=R$5$l$F$$$k>r7o$d%k!<%k$,7Q>5$5$l$k$3$H$K$J$j$^$9!#(B</dd> + + <dt><code>MaxRedirects=<var>number</var></code></dt> + <dd>$B%G%#%l%/%H%jKh$N(B <code>RewriteOptions</code> $B$K$h$kFbIt%j%@%$%l%/%H$N(B + $BL58B%k!<%W$rKI$0$?$a$K!"(B<code>mod_rewrite</code> $B$O%j%@%$%l%/%H$N(B + $B>e8B$KC#$9$k$H%j%/%(%9%H$rCf;_$7!"(B500 Internal Server Error $B$r1~Ez$H$7$F(B + $BJV$7$^$9!#0l$D$N%j%/%(%9%H$KBP$7$FK\Ev$K(B 10 $B$r1[$($k%j%@%$%l%/%H$,I,MW$J(B + $B>l9g$O!"K>$_$NCM$^$GA}2C$5$;$k$3$H$,$G$-$^$9!#(B</dd> + </dl> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteLog" name="RewriteLog">RewriteLog</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>$B=q<0(B:</strong></a> RewriteLog + <em>file-path</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>$B%G%U%)%k%H(B:</strong></a> <em>$B$J$7(B</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>$B%3%s%F%-%9%H(B:</strong></a> $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H(B<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>$B%*!<%P!<%i%$%I(B:</strong></a> <em>$BE,MQIT2D(B</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>$B%9%F!<%?%9(B:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>$B%b%8%e!<%k(B:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>$B8_49@-(B:</strong></a> Apache + 1.2<br /> + + $B!!(B<p><code>RewriteLog</code> $B%G%#%l%/%F%#%V$O!"(B + $B9T$J$o$l$?$9$Y$F$N=q$-49$(F0:n$r(B + $B%5!<%P$,%m%0$K=q$-9~$`$?$a$N(B + $B%U%!%$%kL>$r@_Dj$7$^$9!#$3$NL>A0$,%9%i%C%7%e(B + ('<code>/</code>') $B$G;O$^$i$J$$>l9g$O(B <em>Server Root</em> + $B$+$i$NAjBP%Q%9$G$"$k$H8+$J$5$l$^$9!#$3$N%G%#%l%/%F%#%V$O(B + $B%5!<%PC10L$N@_Dj$NCf$G0lEY$@$15-=R$5$l$k$Y$-$b$N$G$9!#(B</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>$BCm0U(B</strong>: + $B=q$-49$(F0:n$N%m%.%s%0$rM^@)$9$k$?$a$K(B <em>file-path</em> $B$r(B + <code>/dev/null</code> $B$K$9$k$N$O$*4+$a$G$-$^$;$s!#$3$l$O!"(B + $B=q$-49$(%(%s%8%s$O<B:]$K$O%m%0%U%!%$%k$X$N=PNO$r9T$o$J$$$N$K!"(B + $BL$$@FbItE*$K$O%m%0%U%!%$%k$X$N=PNO$r@8@.$7$F$$$k$+$i$G$9!#(B + <strong>$B$3$l$O4IM}<T$K2?$NMxE@$b$b$?$i$5$:$K(B + $B%5!<%P$N%Q%U%)!<%^%s%9$rDc2<$5$;$k$@$1$G$9(B!</strong> + $B%m%.%s%0$rM^;_$9$k>l9g$O(B <code>RewriteLog</code> + $B%G%#%l%/%F%#%V$r%3%a%s%H%"%&%H$9$k$+!"(B + <code>RewriteLogLevel 0</code> $B$r;H$&$h$&$K$7$F$/$@$5$$(B!</td> + </tr> + </table> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>$B%;%-%e%j%F%#(B</strong>: + $B%m%0%U%!%$%k$r3JG<$9$k%G%#%l%/%H%j$,!"(B + $B%5!<%P$r5/F0$9$k%f!<%60J30$K$b=q$-9~$_2DG=$G$"$k>l9g$K!"(B + $B$J$<%;%-%e%j%F%#$,6<$+$5$l$k$+$K$D$$$F$N>\$7$$@bL@$O!"(B + <a href="../misc/security_tips.html">Apache $B$N%;%-%e%j%F%#$N(B + $B$3$D(B</a> $B%I%-%e%a%s%H$r$4Mw$/$@$5$$!#(B</td> + </tr> + </table> + + <p><strong>$BNc(B:</strong></p> + + <blockquote> +<pre> +RewriteLog "/usr/local/var/apache/logs/rewrite.log" +</pre> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteLogLevel" + name="RewriteLogLevel">RewriteLogLevel</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>$B=q<0(B:</strong></a> RewriteLogLevel + <em>Level</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>$B%G%U%)%k%H(B:</strong></a> + <code>RewriteLogLevel 0</code><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>$B%3%s%F%-%9%H(B:</strong></a> $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H(B<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>$B%*!<%P!<%i%$%I(B:</strong></a> <em>$BE,MQIT2D(B</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>$B%9%F!<%?%9(B:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>$B%b%8%e!<%k(B:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>$B8_49@-(B:</strong></a> Apache + 1.2<br /> + + <p><code>RewriteLogLevel</code> $B%G%#%l%/%F%#%V$G$O!"(B + $B=q$-49$(MQ$N%m%0%U%!%$%k$N>iD9%l%Y%k$r;XDj$7$^$9!#(B + $B%G%U%)%k%H$N%l%Y%k$O(B + 0 $B$G!"$3$l$O0l@Z%m%0$r=q$+$J$$$3$H$r0UL#$7$^$9!#0lJ}(B 9 + $B$b$7$/$O$=$l0J>e$r;XDj$9$k$H!"(B + $B;v<B>e$[$H$s$I$9$Y$F$NF0:n$K$D$$$F%m%0$,<}=8$5$l$^$9!#(B</p> + + <p>$B=q$-49$($N%m%0$r<h$i$J$$$h$&$K$9$k$K$O!"C1$K(B + <em>Level</em> $B$r(B 0 + $B$K$7$^$9!#$3$l$G=q$-49$($K4X$9$k$9$Y$F$N%m%0$,L58z$H$J$j$^$9!#(B + </p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>$BCm0U(B:</strong> <em>Level</em> + $B$KBg$-$JCM$r;XDj$9$k$H!"(BApache $B%5!<%P$NF0:nB.EY$,7`E*$KDc2<$7$^$9(B! + $B=q$-49$(;~$N%m%0%U%!%$%k$G(B <em>Level</em> $B$K(B 2 + $B0J>e$NCM$r;XDj$9$k$N$O%G%P%C%0;~$N$_$K$7$F$*$$$F$/$@$5$$(B!</td> + </tr> + </table> + + <p><strong>$BNc(B:</strong></p> + + <blockquote> +<pre> +RewriteLogLevel 3 +</pre> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteLock" + name="RewriteLock">RewriteLock</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>$B=q<0(B:</strong></a> RewriteLock + <em>file-path</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>$B%G%U%)%k%H(B:</strong></a> <em>$B$J$7(B</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>$B%3%s%F%-%9%H(B:</strong></a> $B%5!<%P@_Dj%U%!%$%k(B<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>$B%*!<%P!<%i%$%I(B:</strong></a> <em>$BE,MQIT2D(B</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>$B%9%F!<%?%9(B:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>$B%b%8%e!<%k(B:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>$B8_49@-(B:</strong></a> Apache + 1.3<br /> + + <p>$B$3$N%G%#%l%/%F%#%V$O!"(Bmod_rewrite $B$,(B <samp>RewriteMap</samp> + <em>$B%W%m%0%i%`(B</em>$B$HDL?.$9$k$N$KI,MW$J!"(B + $BF14|MQ%m%C%/%U%!%$%k$NL>A0$r%;%C%H$7$^$9!#(BRewriteMap $B$G(B + $B%W%m%0%i%`$r;H$$$?$$>l9g$K$O!"$3$N%m%C%/%U%!%$%k$K(B(NFS + $B%^%&%s%H$5$l$?%G%P%$%9$G$O$J$/(B)$B%m!<%+%k%Q%9$r@_Dj$7$^$9!#(B + $B$=$l0J30$N%?%$%W$N(B RewriteMap $B$r;H$&>l9g$K$O!"(B + $B@_Dj$9$kI,MW$O$"$j$^$;$s!#(B</p> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteMap" name="RewriteMap">RewriteMap</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>$B=q<0(B:</strong></a> RewriteMap + <em>MapName</em> <em>MapType</em>:<em>MapSource</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>$B%G%U%)%k%H(B:</strong></a>$B%G%U%)%k%H$G$O;HMQ$5$l$J$$(B + <br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>$B%3%s%F%-%9%H(B:</strong></a> $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H(B<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>$B%*!<%P!<%i%$%I(B:</strong></a> <em>$BE,MQIT2D(B</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>$B%9%F!<%?%9(B:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>$B%b%8%e!<%k(B:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>$B8_49@-(B:</strong></a> Apache 1.2 + ($B0lIt$N$_(B), Apache 1.3<br /> + + + <p><code>RewriteMap</code> $B%G%#%l%/%F%#%V$O!"(B + $B%^%C%T%s%04X?t$r;H$C$F%k!<%kCV49J8;zNs$NFbIt$G;H$($k(B + <em>$B=q$-49$(%^%C%W(B</em>$B$rDj5A$7$^$9!#$3$l$K$h$j!"(B + $B%-!<$r8!:w$9$k:]$K!"%U%#!<%k%I$rA^F~$7$?$jCV49$7$?$j$G$-$^$9!#(B + $B8!:wBP>]$K$O$$$m$$$m$J%?%$%W$,;H$($^$9!#(B</p> + + <p><a id="mapfunc" name="mapfunc"><em>MapName</em></a> + $B$O%^%C%W$NL>A0$G$9!#0J2<$N=q<0$N$I$A$i$+$K$h$j!"(B + $B=q$-49$(%k!<%k$NCV49J8;zNs$G;H$o$l$k(B + $B%^%C%T%s%04X?t$r;XDj$9$k$N$K;H$o$l$^$9!#(B</p> + + <blockquote> + <strong><code>${</code> <em>MapName</em> <code>:</code> + <em>LookupKey</em> <code>}</code><br /> + <code>${</code> <em>MapName</em> <code>:</code> + <em>LookupKey</em> <code>|</code> <em>DefaultValue</em> + <code>}</code></strong> + </blockquote> + $B$3$N$h$&$J=q<0$,8=$l$k$H!"(B<em>MapName</em> $B$H$$$&L>A0$N%^%C%W$NCf$N%-!<(B + <em>LookupKey</em> $B$,8!:w$5$l$^$9!#(B + $B%-!<$,8+$D$+$l$P!"$3$N%^%C%W4X?t$N=q<0$NItJ,$O(B <em>SubstValue</em> + $B$K$h$jCV49$5$l$^$9!#%-!<$,8+$D$+$i$J$$>l9g!"(B + <em>DefaultValue</em> $B$,$"$l$P$=$l$GCV49$5$l!"(B<em>DefaultValue</em> + $B$,;XDj$5$l$F$$$J$1$l$P6uJ8;zNs$KCV49$5$l$^$9!#(B + + <p>$B0J2<$N$h$&$J(B <em>MapType</em> $B$H(B <em>MapSource</em> + $B$r;H$C$?AH$_9g$o$;$r;HMQ$G$-$^$9(B:</p> + + <ul> + <li> + <strong>$BI8=`$N%W%l!<%s%F%-%9%H(B</strong><br /> + MapType: <code>txt</code>, MapSource: + Unix $B%U%!%$%k%7%9%F%`$NM-8z$JDL>o%U%!%$%k$X$N%Q%9(B + + <p>$B$3$l$OI8=`$N=q$-49$(%^%C%W5!G=$G$9!#(B + <em>MapSource</em> $B$O6uGr9T$d%3%a%s%H9T(B($B9TF,$,(B + '#' $BJ8;z$G;O$^$k9T(B)$B!"<c$7$/$O0J2<$N$h$&$J(B + $B%Z%"$,0l9TKh$K=q$+$l$F$$$k$h$&$JIaDL$N(B ASCII + $B%U%!%$%k$G$9!#(B</p> + + <blockquote> + <strong><em>MatchingKey</em> + <em>SubstValue</em></strong> + </blockquote> + + <p>$BNc(B:</p> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +## +## map.txt -- rewriting map +## + +Ralf.S.Engelschall rse # Bastard Operator From Hell +Mr.Joe.Average joe # Mr. Average +</pre> + </td> + </tr> + </table> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +RewriteMap real-to-user txt:/path/to/file/map.txt +</pre> + </td> + </tr> + </table> + </li> + + <li> + <strong>$B%i%s%@%`$J%W%l!<%s%F%-%9%H(B</strong><br /> + MapType: <code>rnd</code>, MapSource: + Unix $B%U%!%$%k%7%9%F%`$NM-8z$JDL>o%U%!%$%k$X$N%Q%9(B + + <p>$B$3$l$OA0=R$NI8=`%W%l!<%s%F%-%9%H$H$[$\F1$8$G$9$,!"$=$l$K2C$($F(B + $B@lMQ$N8e=hM}5!G=$r;}$C$F$$$^$9(B: $BCM$r8!:w$7$?8e!"$=$NCM$O(B ``or'' + $B$N0UL#$r;}$D(B ``<code>|</code>'' $BJ8;z$K$7$?$,$C$F%Q!<%9$5$l$^$9!#(B + $B$D$^$j$3$l$i$OJQ498uJd$rMeNs$7$F$*$j!"(B + $B<B:]$KJV$5$l$kCM$O$3$l$i$NCf$+$i%i%s%@%`$KA*$P$l$^$9!#(B + $B$3$l$O0l8+L/$J46$8$,$7$F0UL#$,$J$5$=$&$K;W$($^$9$,!"(B + $B<B:]$K8!:w$7$?CM$,%5!<%PL>$K$J$k$h$&$J(B + $B%j%P!<%9%W%m%-%7$rMQ$$$?Ii2YJ,;6MQ$K(B + $B@_7W$5$l$F$$$^$9!#(B + $BNc$($P(B:</p> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +## +## map.txt -- rewriting map +## + +static www1|www2|www3|www4 +dynamic www5|www6 +</pre> + </td> + </tr> + </table> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +RewriteMap servers rnd:/path/to/file/map.txt +</pre> + </td> + </tr> + </table> + </li> + + <li> + <strong>$B%O%C%7%e%U%!%$%k(B</strong><br /> + MapType: <code>dbm</code>, MapSource: + Unix $B%U%!%$%k%7%9%F%`$NM-8z$JDL>o%U%!%$%k$X$N%Q%9(B + + <p>$B%U%!%$%k$NFbMF$N0UL#$O(B<em>$B%W%l!<%s%F%-%9%H(B</em>$B%U%)!<%^%C%H(B + $B$HF1$8$G$9$,!"(B + $B9bB.$J8!:w$r9T$&$?$a$K:GE,2=$,;\$5$l$?(B + NDBM $B%U%)!<%^%C%H$H$$$&%P%$%J%j%U%!%$%k(B + $B$r%=!<%9$H$7$F;H$&$3$H$b$G$-$^$9!#$3$N$h$&$J%U%!%$%k$O!"(B + NDBM $B%D!<%k$r;H$C$?$j!"0J2<$N$h$&$J(B perl + $B%9%/%j%W%H$r;H$C$F:n$k$3$H$,$G$-$^$9!#(B</p> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +#!/path/to/bin/perl +## +## txt2dbm -- convert txt map to dbm format +## + +use NDBM_File; +use Fcntl; + +($txtmap, $dbmmap) = @ARGV; + +open(TXT, "<$txtmap") or die "Couldn't open $txtmap!\n"; +tie (%DB, 'NDBM_File', $dbmmap,O_RDWR|O_TRUNC|O_CREAT, 0644) or die "Couldn't create $dbmmap!\n"; + +while (<TXT>) { + next if (/^\s*#/ or /^\s*$/); + $DB{$1} = $2 if (/^\s*(\S+)\s+(\S+)/); +} + +untie %DB; +close(TXT); +</pre> + </td> + </tr> + </table> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +$ txt2dbm map.txt map.db +</pre> + </td> + </tr> + </table> + </li> + + <li> + <strong>$BFbIt4X?t(B</strong><br /> + MapType: <code>int</code>, MapSource: $BFbIt(B Apache $B4X?t(B + + <p>$B%=!<%9$H$7$F!"FbIt(B Apache $B4X?t$r;H$&$3$H$b$G$-$^$9!#(B + $B8=;~E@$G$O%(%s%I%f!<%6$,<+J,MQ$KFH<+$N$b$N$r:n$k$3$H$O$G$-$^$;$s$,!"(B + $B0J2<$N$b$N$,MQ0U$5$l$F$$$^$9!#(B</p> + + <ul> + <li><strong>toupper</strong>:<br /> + $B8+$D$+$C$?%-!<$r$9$Y$FBgJ8;z$KJQ49$9$k!#(B</li> + + <li><strong>tolower</strong>:<br /> + $B8+$D$+$C$?%-!<$r$9$Y$F>.J8;z$KJQ49$9$k!#(B</li> + + <li><strong>escape</strong>:<br /> + $B8+$D$+$C$?%-!<$NCf$NFC<lJ8;z$r(B 16 + $B?J%(%s%3!<%G%#%s%0$KJQ49$9$k!#(B</li> + + <li><strong>unescape</strong>:<br /> + $B8+$D$+$C$?%-!<$NCf$N(B 16 $B?J%(%s%3!<%G%#%s%0$rFC<lJ8;z$KLa$9!#(B</li> + </ul> + </li> + + <li> + <strong>$B30It$N=q$-49$(%W%m%0%i%`(B</strong><br /> + MapType: <code>prg</code>, MapSource: + Unix $B%U%!%$%k%7%9%F%`$NM-8z$JDL>o%U%!%$%k$X$N%Q%9(B + + <p>$B%=!<%9$K$O%^%C%W%U%!%$%k0J30$K%W%m%0%i%`$r;H$&$3$H$b$G$-$^$9!#(B + $B%W%m%0%i%`$O9%$-$J8@8l$rA*Br$9$k$3$H$,$G$-$^$9$,!"(B + $B:n@.$5$l$?$b$N$O<B9T2DG=%U%!%$%k(B + (<em>$B$9$J$o$A(B</em>$B%*%V%8%'%/%H%3!<%I!"<c$7$/$O(B 1 $B9TL\$K(B ' + <code>#!/path/to/interpreter</code>' + $B$N$h$&$J%^%8%C%/%/%C%-!<%H%j%C%/$NF~$C$?%9%/%j%W%H(B) + $B$G$J$1$l$P$J$j$^$;$s!#(B</p> + + <p>$B$3$N%W%m%0%i%`$O(B Apache $B%5!<%P$N5/F0;~$K0lEY$@$15/F0$5$l!"(B + <code>stdin</code> $B$*$h$S(B <code>stdout</code> + $B%U%!%$%k%O%s%I%k$rDL$7$F!"=q$-49$(%(%s%8%s$H$N$d$j$H$j$r9T$$$^$9!#(B + $B$3$N%W%m%0%i%`$O!"3F!9$N%^%C%W4X?t$N8!:w$N$?$S$K!"(B + $B8!:wBP>]$N%-!<$r!"2~9TJ8;z$G=*C<$5$l$?J8;zNs$H$7$F(B + <code>stdin</code> $B$+$i<u$1<h$j$^$9!#(B + $B$=$7$F!"CM$,8+$D$+$l$P2~9TJ8;z$G=*C<$5$l$?J8;zNs$rJV$7!"(B + $B8+$D$+$i$J$1$l$P(B + (<em>$B$9$J$o$A(B</em>$B!"M?$($i$l$?%-!<$KBP1~$9$kCM$,$J$$(B)$B!"(B + 4 $BJ8;z$NJ8;zNs(B ``<code>NULL</code>'' $B$rJV$5$J$1$l$P$J$j$^$;$s!#(B + 1:1 $B$N%^%C%W(B(<em>$B$9$J$o$A(B</em>$B%-!<(B == $BCM(B) + $B$r<B8=$9$kC1=c$J%W%m%0%i%`Nc$H$7$F$O!"0J2<$N$h$&$K$J$j$^$9(B:</p> + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +#!/usr/bin/perl +$| = 1; +while (<STDIN>) { + # ...put here any transformations or lookups... + print $_; +} +</pre> + </td> + </tr> + </table> + + <p>$B$7$+$7!"==J,$K5$$r$D$1$F$[$7$$$3$H$,$"$j$^$9(B:<br /> + </p> + + <ol> + <li>``<em>Keep it simple, stupid + ($BC1=c$J$^$^$K$7$F$*$1!"GO</LnO:(B!)$B!W(B</em>'' (KISS) + $B$H$$$&86B'$K=>$C$F$/$@$5$$!#$b$7$3$N%W%m%0%i%`$,%O%s%0$7$F$7$^$&$H!"(B + $B$=$N%k!<%k$,8=$l$?=V4V$K(B Apache + $B%5!<%P<+BN$,%O%s%0$7$F$7$^$$$^$9!#(B</li> + + <li>$B$"$j$,$A$J4V0c$$$H$7$F$O(B: <code>stdout</code> + $B$KBP$7$F%P%C%U%!$5$l$?F~=PNO$r;H$C$F$O$J$j$^$;$s(B! + $B$3$l$r$d$k$HL58B%k!<%W$K%O%^$C$F$7$^$$$^$9(B! + $B$@$+$i>e$N%3!<%I$G$b(B ``<code>$|=1</code>'' + $B$H$d$C$F$k$s$G$9!D!#(B</li> + + <li><samp>RewriteLock</samp> + $B%G%#%l%/%F%#%V$r;H$C$F%m%C%/%U%!%$%k$rDj5A$7!"(Bmod_rewrite + $B$,Ev3:%W%m%0%i%`$X$NDL?.$KF14|$r<h$l$k$h$&$K$7$F$/$@$5$$!#(B + $B%G%U%)%k%H$G$O$=$N$h$&$JF14|$O9T$o$l$^$;$s!#(B</li> + </ol> + </li> + </ul> + <code>RewriteMap</code> $B%G%#%l%/%F%#%V$O2?EY$G$b=q$/$3$H$,$G$-$^$9!#(B + $B%^%C%T%s%04X?t$4$H$K(B <code>RewriteMap</code> + $B$r;H$C$F=q$-49$(MQ%^%C%W%U%!%$%k$r@k8@$7$^$9!#(B + $B%G%#%l%/%H%j$N%3%s%F%-%9%HFbIt$G%^%C%W$r(B<strong>$B@k8@$9$k(B</strong> + $B$3$H$O$G$-$^$;$s$,!"%G%#%l%/%H%j$N%3%s%F%-%9%H$G$3$N%^%C%W$r(B + <strong>$B;H$&(B</strong>$B$3$H$O$b$A$m$s2DG=$G$9!#(B + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>$BCm0U(B:</strong> $B%W%l!<%s%F%-%9%H$H(B DBM $B%U%)!<%^%C%H(B + $B$N%U%!%$%k$K4X$7$F$O!"%^%C%W%U%!%$%k$N(B <code>mtime</code> + $B$,JQ99$5$l$k$+$^$?$O%5!<%P$,:F5/F0$5$l$k$^$G!"(B + $B8!:w$5$l$?%-!<$O%a%b%jFb$K%-%c%C%7%e$5$l$^$9!#(B + $B$G$9$+$i!"(B<strong>$BKh2s$N(B</strong>$B%j%/%(%9%H$G;H$o$l$k(B + $B%^%C%W4X?t$r%k!<%kFb$K=q$/$3$H$,$G$-$^$9!#(B + $B30It8!:w$O0lEY$7$+9T$o$l$J$$$N$G!"$3$l$G$bBg>fIW$J$N$G$9!#(B</td> + </tr> + </table> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteBase" + name="RewriteBase">RewriteBase</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>$B=q<0(B:</strong></a> RewriteBase + <em>URL-path</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>$B%G%U%)%k%H(B:</strong></a> <em>$B%G%U%)%k%H$OJ*M}(B + $B%G%#%l%/%H%j$N%Q%9(B</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>$B%3%s%F%-%9%H(B:</strong></a> $B%G%#%l%/%H%j(B, .htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>$B%*!<%P!<%i%$%I(B:</strong></a> + <em>FileInfo</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>$B%9%F!<%?%9(B:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>$B%b%8%e!<%k(B:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>$B8_49@-(B:</strong></a> Apache + 1.2<br /> + + <p><code>RewriteBase</code> + $B%G%#%l%/%F%#%V$O!"%G%#%l%/%H%j$4$H$N=q$-49$($K$*$$$F%Y!<%9$H$J$k(B + URL $B$rL@<(E*$K;XDj$9$k$b$N$G$9!#0J2<$G<($9$h$&$K!"(B + <code>RewriteRule</code> $B$O%G%#%l%/%H%j$4$H$N@_Dj%U%!%$%k(B + (<code>.htaccess</code>) $B$G;H$($^$9!#(B + $B$=$3$G$O!"$3$l$O%m!<%+%k$K?6$kIq$$$^$9!#(B<em>$B$9$J$o$A(B</em>$B!"(B + $B$3$N=hM}CJ3,$G$O%m!<%+%k%G%#%l%/%H%j$N@\F,<-$,<h$j=|$+$l!"(B + $B$=$N;D$j$NItJ,$KBP$7$F$N$_=q$-49$(%k!<%k$,E,MQ$5$l$^$9!#(B + $B$=$7$F=q$-49$(8e!"<h$j=|$+$l$?ItJ,$,:FEY<+F0E*$K%Q%9$KIU2C$5$l$^$9!#(B + </p> + + <p>$B?7$7$$(B URL $B$KBP$9$kCV49$,H/@8$9$k$H!"$3$N%b%8%e!<%k$OEv3:(B URL + $B$r%5!<%P=hM}$K:FEjF~$7$J$1$l$P$J$j$^$;$s!#$3$l$r9T$&$K$O!"BP1~$9$k(B + URL $B$N@\F,<-!"<c$7$/$O(B URL + $B$N%Y!<%9$,2?$J$N$+$rCN$kI,MW$,$"$j$^$9!#(B + $B%G%U%)%k%H$G$O$3$N@\F,<-$O%U%!%$%k%Q%9$=$N$b$N$KBP1~$7$F$$$^$9!#(B + <strong>$B$7$+$7$J$,$i!"$[$H$s$I$N(B Web $B%5%$%H$G$O(B URL + $B$OJ*M}E*$J%U%!%$%kL>$N%Q%9$rD>@\;X$7$F$$$k(B *$B$o$1$G$O$J$$(B* + $B$N$G!"0lHLE*$K$3$N2>Dj$O4V0c$C$F$$$k$3$H$K$J$j$^$9(B</strong>$B!#(B + $B$=$N$?$a!"(B<code>RewriteBase</code> $B%G%#%l%/%F%#%V$r;H$C$F@5$7$$(B + URL $B$N@\F,<-$r;XDj$7$F$d$i$J$1$l$P$J$i$J$$$N$G$9!#(B</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>$BCm0U(B:</strong> $B$b$7$"$J$?$N(B Web $B%5!<%P$N(B URL + $B$,J*M}E*$J%U%!%$%k%Q%9$rD>@\;X$7$F$$$k$N$G(B<strong>$B$J$1(B</strong>$B$l$P!"(B + <code>RewriteRule</code> + $B%G%#%l%/%F%#%V$r;H$*$&$H$7$F$$$k%G%#%l%/%H%j$9$Y$F$K$*$$$F!"3F(B + <code>.htaccess</code> $B%U%!%$%k$G(B <code>RewriteBase</code> + $B%G%#%l%/%F%#%V$r;H$o$J$1$l$P$J$j$^$;$s!#(B</td> + </tr> + </table> + + <p><strong>$BNc(B:</strong></p> + + <blockquote> + $B0J2<$O!"%G%#%l%/%H%j$4$H$N@_Dj%U%!%$%k$@$H;W$C$F$/$@$5$$!'(B + + <table border="0" cellspacing="1" cellpadding="5" + bgcolor="#F0F0F0"> + <tr> + <td> +<pre> +# +# /abc/def/.htaccess -- $B%G%#%l%/%H%j(B /abc/def $B$N$?$a$N%G%#%l%/%H%jJL@_Dj%U%!%$%k(B +# $B;29M!'(B/abc/def $B$O(B $B%Q%9(B /xyz $B$NJ*M}%Q%9L>$G$"$k!#(B<em>$B$9$J$o$A(B</em>$B%5!<%P$K$O(B +# 'Alias /xyz /abc/def' <em>$B$H$$$C$?(B</em>$B%G%#%l%/%F%#%V$N@_Dj$,$"$k!#(B +# + +RewriteEngine On + +# $BJ*M}E*$J%Q%9$N@\F,<-$G$"$k(B /abc/def $B$G$J$/!"(B/xyz $B$rDL$7$F(B +# $B%"%/%;%9$7$F$$$k$3$H$r%5!<%P$KCN$i$;$k!#(B +RewriteBase /xyz + +# $B$3$l$,=q$-49$(%k!<%k(B +RewriteRule ^oldstuff\.html$ newstuff.html +</pre> + </td> + </tr> + </table> + + <p>$B>e5-$NNc$G$O!"(B<code>/xyz/oldstuff.html</code> + $B$X$N%j%/%(%9%H$GJ*M}%U%!%$%k(B <code>/abc/def/newstuff.html</code> + $B$X$N@5$7$$=q$-49$(A`:n$,9T$o$l$^$9!#(B</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td> + <font size="-1"><strong>Apache + $B%O%C%+!<$N$?$a$NCm<a(B:</strong><br /> + $B0J2<$N%j%9%H$G<($7$F$$$k$N$O!"(B + $BFbIt=hM}%9%F%C%W$K4X$9$k>\:Y>pJs$G$9(B:</font> +<pre> +<font size="-1">$B%j%/%(%9%H(B: + /xyz/oldstuff.html + +$BFbIt=hM}!'(B + /xyz/oldstuff.html -> /abc/def/oldstuff.html (per-server Alias) + /abc/def/oldstuff.html -> /abc/def/newstuff.html (per-dir RewriteRule) + /abc/def/newstuff.html -> /xyz/newstuff.html (per-dir RewriteBase) + /xyz/newstuff.html -> /abc/def/newstuff.html (per-server Alias) + +$B=hM}7k2L!'(B + /abc/def/newstuff.html +</font> +</pre> + <font size="-1">$B$3$l$OHs>o$KJ#;($K8+$($k$b$N$N!"(BApache + $B$NFbIt=hM}$K4X$9$k@5$7$$F0$-$G$9!#$J$<$J$i!"(B + $B%G%#%l%/%H%jC10L$N=q$-49$(A`:n$O=hM}$NCf$K$*$$$F(B + $BMh$k$N$,CY$9$.$k$+$i$G$9!#$=$N$?$a=q$-49$($,9T$J$o$l$k$H!"(B + ($B=q$-49$($,9T$o$l$?(B)$B%j%/%(%9%H$O(B Apache + $B%+!<%M%k$NCf$K:FEjF~$5$l$J$1$l$P$J$j$^$;$s(B! + $B$7$+$7(B: $B$3$l$O?<9o$J%*!<%P!<%X%C%I$rH<$&$h$&$K8+$($k$b$N$N!"(B + $B<B:]$K$OBg$7$?;v$O$"$j$^$;$s!#$3$N:FEjF~$O40A4$K(B + Apache $B%5!<%P$NFbIt$G5/$3$k;v$G$"$j!"(BApache + $B$NFbIt$K$*$1$k$=$NB>$NB?$/$NF0:nCf$K$bF1MM$N$3$H$,(B + $B5/$3$C$F$$$k$+$i$G$9!#$J$N$G!"(B + $B$3$N@_7W$H<BAu$O@5$7$$$b$N$J$N$G$9!#(B + </font> + </td> + </tr> + </table> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteCond" + name="RewriteCond">RewriteCond</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>$B=q<0(B:</strong></a> RewriteCond + <em>TestString</em> <em>CondPatter</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>$B%G%U%)%k%H(B:</strong></a> <em>$B$J$7(B</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>$B%3%s%F%-%9%H(B:</strong></a> $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H!"%G%#%l%/%H%j!"(B.htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>$B%*!<%P!<%i%$%I(B:</strong></a> + <em>FileInfo</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>$B%9%F!<%?%9(B:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>$B%b%8%e!<%k(B:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>$B8_49@-(B:</strong></a> Apache 1.2 + ($BItJ,E*$K(B), Apache 1.3<br /> + + + <p><code>RewriteCond</code> $B%G%#%l%/%F%#%V$O%k!<%k>r7o$rDj5A$7$^$9!#(B + <code>RewriteRule</code> $B%G%#%l%/%F%#%V$NA0$K0l$D0J>e$N(B + <code>RewriteCond</code> $B%G%#%l%/%F%#%V$rCV$/$3$H$,$G$-$^$9!#(B + $B$=$l0J9_$N=q$-49$(%k!<%k$O!"$=$N%Q%?!<%s$,8=:_$N(B URI + $B$N>uBV$H%^%C%A$7!"(B<strong>$B$+$D(B</strong>$B$3$l$i$NDI2C>r7o$,(B + $BE,MQ$5$l$k>l9g$K$N$_;H$o$l$^$9!#(B</p> + + <p><em>TestString</em>$B$OJ8;zNs$G$"$j!"%W%l!<%s%F%-%9%H$K2C$(!"(B + $B0J2<$N3HD%9=B$$r;}$D$3$H$,$G$-$^$9(B:</p> + + <ul> + <li> + <strong>RewriteRule $B8eJ};2>H(B</strong>: + $B$3$N=q<0$G!"8eJ};2>H$rI=$7$^$9!#(B + + <blockquote> + <strong><code>$N</code></strong> + </blockquote> + (0 <= N <= 9) $B$3$l$O!"BP1~$9$k(B <code>RewriteRule</code> + $B%G%#%l%/%F%#%V(B($B8=:_$N(B<code>RewriteCond</code> + $B%G%#%l%/%F%#%V$N%V%m%C%/$N<!$K$"$k$b$N(B)$B$N(B + ($B3g8L$G0O$s$G(B)$B%0%k!<%W2=$5$l$?%Q%?!<%s$X$N%"%/%;%9$rDs6!$7$^$9!#(B + </li> + + <li> + <strong>RewriteCond $B8eJ};2>H(B</strong>: + $B$3$N=q<0$G!"8eJ};2>H$rI=$7$^$9!#(B + + <blockquote> + <strong><code>%N</code></strong> + </blockquote> + (1 <= N <= 9) + $B$3$l$O!"8=:_$N>r7o%V%m%C%/$NCf$G(B<code>RewriteCond</code> $B%G%#%l%/%F%#%V(B + $B$K:G8e$K%^%C%A$7$?(B + ($B3g8L$G0O$s$G(B)$B%0%k!<%W2=$5$l$?%Q%?!<%s$X$N%"%/%;%9$rDs6!$7$^$9!#(B + </li> + + <li> + <strong>RewriteMap $B3HD%(B</strong>: + $B$3$N=q<0$G!"3HD%$rI=$7$^$9!#(B + + <blockquote> + <strong><code>${mapname:key|default}</code></strong> + </blockquote> + $B>\:Y$O(B <a href="#mapfunc">RewriteMap + $B$N%I%-%e%a%s%H(B</a>$B$r;2>H$N$3$H!#(B + </li> + + <li> + <strong>$B%5!<%PJQ?t(B</strong>: $B0J2<$OJQ?t$rI=$7$^$9!#(B + + <blockquote> + <strong><code>%{</code> <em>$BJQ?tL>(B</em> + <code>}</code></strong> + </blockquote> + <em>$BJQ?tL>(B</em>$B$O0J2<$N0lMw$K$"$kJ8;zNs$N$$$:$l$+$G$9(B: + + <table bgcolor="#F0F0F0" cellspacing="0" cellpadding="5"> + <tr> + <td valign="top"> + <strong>HTTP $B%X%C%@(B:</strong> + + <p><font size="-1">HTTP_USER_AGENT<br /> + HTTP_REFERER<br /> + HTTP_COOKIE<br /> + HTTP_FORWARDED<br /> + HTTP_HOST<br /> + HTTP_PROXY_CONNECTION<br /> + HTTP_ACCEPT<br /> + </font></p> + </td> + + <td valign="top"> + <strong>$B%3%M%/%7%g%s(B & $B%j%/%(%9%H(B:</strong> + + <p><font size="-1">REMOTE_ADDR<br /> + REMOTE_HOST<br /> + REMOTE_USER<br /> + REMOTE_IDENT<br /> + REQUEST_METHOD<br /> + SCRIPT_FILENAME<br /> + PATH_INFO<br /> + QUERY_STRING<br /> + AUTH_TYPE<br /> + </font></p> + </td> + </tr> + + <tr> + <td valign="top"> + <strong>$B%5!<%PFbItJQ?t(B:</strong> + + <p><font size="-1">DOCUMENT_ROOT<br /> + SERVER_ADMIN<br /> + SERVER_NAME<br /> + SERVER_ADDR<br /> + SERVER_PORT<br /> + SERVER_PROTOCOL<br /> + SERVER_SOFTWARE<br /> + </font></p> + </td> + + <td valign="top"> + <strong>$B%7%9%F%`4XO"(B:</strong> + + <p><font size="-1">TIME_YEAR<br /> + TIME_MON<br /> + TIME_DAY<br /> + TIME_HOUR<br /> + TIME_MIN<br /> + TIME_SEC<br /> + TIME_WDAY<br /> + TIME<br /> + </font></p> + </td> + + <td valign="top"> + <strong>$BFC<l$J$b$N(B:</strong> + + <p><font size="-1">API_VERSION<br /> + THE_REQUEST<br /> + REQUEST_URI<br /> + REQUEST_FILENAME<br /> + IS_SUBREQ<br /> + </font></p> + </td> + </tr> + </table> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td> + <p><strong>$BCm0U(B:</strong> + $B$3$l$i$NJQ?t$O!"$9$Y$FF1MM$NL>A0$r;}$D(B HTTP MIME $B%X%C%@$d(B + Apache $B%5!<%P$N(B C $BJQ?t!"$^$?$O(B Unix $B%7%9%F%`$N(B + <code>struct tm</code> $B%U%#!<%k%I$KBP1~$7$^$9!#(B + $B$[$H$s$I$N$b$N$O!"%^%K%e%"%k$d(B CGI + $B;EMM$N$I$3$+$K@bL@$,$"$j$^$9!#$3$NCf$G(B mode_rewrite + $B$GFCJL$J0UL#$r;}$D$b$N$K0J2<$N$b$N$,$"$j$^$9(B:</p> + + <dl> + <dt><code>IS_SUBREQ</code></dt> + + <dd>$B$3$l$O!"%5%V%j%/%(%9%H$r=hM}Cf$O(B "true" + $B$K!"$=$&$G$J$1$l$P(B "false" $B$K$J$j$^$9!#(B + $BM?$($i$l$?%?%9%/$r40N;$9$k$?$a$KDI2C$N%U%!%$%k$d(B URI + $B$r2r7h$9$kI,MW$,$"$k%b%8%e!<%k$O!"(B + $B%5%V%j%/%(%9%H$r@8@.$9$k>l9g$,$"$j$^$9!#(B</dd> + + <dt><code>API_VERSION</code></dt> + + <dd>$B$3$l$O8=:_$N(B httpd $B$N%S%k%I$K$*$1$k(B Apache + $B%b%8%e!<%k(B API($B%5!<%P$H%b%8%e!<%k4V$NFbIt%$%s%?!<%U%'!<%9(B) + $B$N%P!<%8%g%s$G$"$j!"(Binclude/ap_mmn.h $B$GDj5A$5$l$F$$$^$9!#(B + $B%b%8%e!<%k(B API $B$N%P!<%8%g%s$O;HMQ$7$F$$$k(B Apache + $B$N%P!<%8%g%s(B($BNc$($P(B Apche 1.3.14 $B$G$"$l$P(B + 19990320:10) $B$KBP1~$7$^$9$,!"(B + $B$3$l$O<g$K%b%8%e!<%k$N:n<T$,4X?4$r;}$D$b$N$G$9!#(B</dd> + + <dt><code>THE_REQUEST</code></dt> + + <dd>$B%V%i%&%6$+$i%5!<%P$KAw$i$l$?(B HTTP + $B%j%/%(%9%H$N40A4$J$b$N(B($BNc$($P!"(B + "<code>GET /index.html HTTP/1.1</code>")$B!#(B + $B$3$l$K$O!"%V%i%&%6$+$iAw$i$l$?DI2C%X%C%@$O0l@Z4^$_$^$;$s!#(B + </dd> + + <dt><code>REQUEST_URI</code></dt> + + <dd>HTTP $B%j%/%(%9%H9T$G%j%/%(%9%H$5$l$?%j%=!<%9(B + ($B>e5-$NNc$G$O(B "/index.html" $B$,$=$l$K$"$?$j$^$9(B)$B!#(B</dd> + + <dt><code>REQUEST_FILENAME</code></dt> + + <dd>$B%j%/%(%9%H$K%^%C%A$7$?%U%!%$%k$^$?$O%9%/%j%W%H$N!"(B + $B40A4$J%m!<%+%k%U%!%$%k%7%9%F%`$N%Q%9!#(B</dd> + </dl> + </td> + </tr> + </table> + </li> + </ul> + + <p>$B9MN8;v9`(B:</p> + + <ol> + <li>SCRIPT_FILENAME $B$*$h$S(B REQUEST_FILENAME $B$K$OF1$8L>A0!"(B + <em>$B$9$J$o$A(B</em>$B!"(BApache $B%5!<%P$N(B <code>request_rec</code> + $BFbIt9=B$BN$NCf$N(B <code>filename</code> + $B%U%#!<%k%I$NCM$,F~$C$F$$$^$9!#A0<T$OC1$K$h$/CN$i$l$F$$$k(B CGI + $BJQ?tL>$G$"$k$N$KBP$7!"8e<T$O(B (<code>request_rec</code> + $B%U%#!<%k%I$N(B <code>uri</code> $B$NCM$,F~$C$F$$$k(B)REQUEST_URI + $B$KBP1~$9$k$b$N$G$9!#(B</li> + + <li><em>$BJQ?t(B</em>$B$KG$0U$N4D6-JQ?t$r;XDj$G$-$kFCJL$J=q<0(B + <code>%{ENV:$BJQ?t(B}</code> + $B$,$"$j$^$9!#$3$l$O(B Apache + $B$NFbIt9=B$BN<c$7$/$O(B($B$=$3$KB8:_$7$J$1$l$P(B)Apache + $B%5!<%P%W%m%;%9$,H/9T$9$k(B <code>getenv()</code> + $B$rDL$7$F8!:w$5$l$^$9!#(B</li> + + <li> + <em>$B%X%C%@(B</em>$B$KG$0U$N(B HTTP MIME $B%X%C%@L>$r;XDj$G$-$kFCJL$J=q<0(B + <code>%{HTTP:$B%X%C%@(B}</code>$B$,$"$j$^$9!#$3$l$O(B + HTTP $B%j%/%(%9%H$+$i8!:w$5$l$^$9!#(B + $BNc(B: <code>%{HTTP:Proxy-Connection}</code> $B$O(B HTTP $B%X%C%@$N(B + ``<code>Proxy-Connection:</code>'' $B$NCM$G$9!#(B</li> + + <li>$BA0J};2>H$r9T$J$C$FFbIt$N(B(URL $B%Y!<%9$N(B) + $B%5%V%j%/%(%9%H$r<B9T$7$F(B<em>$BJQ?t(B</em>$B$N:G=*CM$r7hDj$9$kFCJL$J=q<0(B + <code>%{LA-U:$BJQ?t(B}</code> $B$,$"$j$^$9!#(B + $B<B:]$K$O(B API $B%U%'!<%:$N8e$N$[$&$G%;%C%H$5$l$k$?$a$K!"(B + $B8=;~E@$G$O%"%/%;%9$G$-$J$$$h$&$JJQ?t$r;H$C$F=q$-49$($r(B + $B9T$J$$$?$$>l9g$K;HMQ$7$^$9!#Nc$($P!"%5!<%PC10L$N%3%s%F%-%9%H(B + (<code>httpd.conf</code> $B%U%!%$%k(B) $B$G(B <code>REMOTE_USER</code> + $BJQ?t$K$7$?$,$C$F=q$-49$($r9T$$$?$$>l9g$K$O!"(B + <code>%{LA-U:REMOTE_USER}</code> + $B$r;HMQ$7$J$1$l$P$J$j$^$;$s!#$J$<$J$i!"$3$NJQ?t$O(B mod_rewrite + $B$,F0:n$9$k(B URL $BJQ49%U%'!<%:$N(B<em>$B8e(B</em>$B$K$"$kG'>Z%U%'!<%:$G(B + $B%;%C%H$5$l$k$b$N$@$+$i$G$9!#0lJ}!"%G%#%l%/%H%jC10L$N%3%s%F%-%9%H(B + (<code>.htaccess</code> $B%U%!%$%k(B) $B$G$O!"(Bmod_rewrite $B$O(B API $B$N(B Fixup + $B%U%'!<%:$rDL$7$F<BAu$5$l$F$*$j!"(B + $BG'>Z%U%'!<%:$O$3$N%U%'!<%:$N(B<em>$BA0(B</em>$B$K9T$J$o$l$k$?$a!"(B + $B$=$3$G$OC1$K(B <code>%{REMOTE_USER}</code> + $B$H$9$k$3$H$,$G$-$k$^$9!#(B</li> + + <li>$BFbIt$N(B($B%U%!%$%kL>%Y!<%9$N(B) + $B%5%V%j%/%(%9%H$r<B9T$7$F(B<em>$BJQ?t(B</em>$B$N:G=*CM$r7hDj$9$kFCJL$J=q<0(B + <code>%{LA-F:$BJQ?t(B}</code> $B$,$"$j$^$9!#(B + $B$[$H$s$I$N>l9g$3$l$OA0=R$N(B LA-U $B$HF1$8$G$9!#(B</li> + </ol> + + <p><em>CondPattern</em> $B$O!">r7o%Q%?!<%s$G!"(B + $B8=:_$N(B <em>TestString</em> $B$N<BBN$KBP$7$FE,MQ$5$l$k@55,I=8=$G$9!#(B + <em>TestString</em> $B$OI>2A$5$l$?8e$K(B <em>CondPattern</em>$B$KBP$7$F(B + $B%^%C%A%s%0$,9T$J$o$l$^$9!#(B</p> + + <p><strong>$BHw9M(B:</strong> <em>CondPattern</em>$B$O!"(B + $BI8=`$N(B<em>$B3HD%@55,I=8=(B</em>$B$K$$$/$D$+DI2C$r9T$C$?$b$N$G$9(B:</p> + + <ol> + <li>'<code>!</code>' $BJ8;z(B($B%(%/%9%/%i%a!<%7%g%s%^!<%/(B) + $B$r%Q%?!<%sJ8;zNs$NA0$K$D$1$k$3$H$G!"(B + $B%^%C%A(B<strong>$B$7$J$$(B</strong>$B%Q%?!<%s$r;XDj$G$-$^$9!#(B</li> + + <li> + <em>CondPattern</em> $B$N$A$g$C$H$7$?JQ<o$b$"$j$^$9!#(B + $B<B:]$N@55,I=8=J8;zNs$NBe$o$j$K0J2<$N$h$&$K;H$&$3$H$,$G$-$^$9(B: + + <ul> + <li>'<strong><CondPattern</strong>' + ($B;z6g$NJB$SE*$K!"$h$j>.$5$$(B)<br /> + <em>CondPattern</em> $B$rC1$J$kJ8;zNs$H$7$F07$$!"(B + $B;z6g$NJB$S$H$7$F(B <em>TestString</em> $B$HHf3S$7$^$9!#(B + <em>TestString</em> $B$,;z6g$NJB$S$H$7$F(B + <em>CondPattern</em> $B$h$j>.$5$$>l9g$K??$K$J$j$^$9!#(B</li> + + <li>'<strong>>CondPattern</strong>' + ($B;z6g$NJB$SE*$K!"$h$jBg$-$$(B)<br /> + <em>CondPattern</em> $B$rC1$J$kJ8;zNs$H$7$F07$$!"(B + $B;z6g$NJB$S$H$7$F(B <em>TestString</em> $B$HHf3S$7$^$9!#(B + <em>TestString</em> $B$,;z6g$NJB$S$H$7$F(B + <em>CondPattern</em> $B$h$jBg$-$$>l9g$K??$K$J$j$^$9!#(B</li> + + <li>'<strong>=CondPattern</strong>' + ($B;z6g$NJB$SE*$KEy$7$$(B)<br /> + <em>CondPattern</em> $B$rC1$J$kJ8;zNs$H$7$F07$$!"(B + $B;z6g$NJB$S$H$7$F(B <em>TestString</em> $B$HHf3S$7$^$9!#(B + <em>TestString</em> $B$,;z6g$NJB$S$H$7$F(B + <em>CondPattern</em> $B$HEy$7$$>l9g!"$9$J$o$A!"Fs$D$NJ8;zNs$,(B + (1 $BJ8;z$:$DHf3S$7$F(B)$B@53N$KEy$7$$>l9g$K??$K$J$j$^$9!#(B + $B$b$7(B <em>CondPattern</em> $B$,C1$J$k(B<samp>""</samp> + ($BFs$D$N0zMQId(B)$B$G$"$l$P!"(B + <em>TestString</em> $B$O6uJ8;zNs$HHf3S$5$l$^$9!#(B</li> + + <li>'<strong>-d</strong>' ($B%G%#%l%/%H%j(B (<strong>d</strong>irectory))<br /> + <em>TestString</em> $B$r%Q%9L>$H$7$F07$$!"$=$l$,B8:_$7$F!"(B + $B$+$D%G%#%l%/%H%j$G$"$l$P??!#(B</li> + + <li>'<strong>-f</strong>' ($BDL>o$N%U%!%$%k(B (<strong>f</strong>ile))<br /> + <em>TestString</em> $B$r%Q%9L>$H$7$F07$$!"$=$l$,B8:_$7$F!"(B + $B$+$DDL>o$N%U%!%$%k$G$"$l$P??!#(B</li> + + <li>'<strong>-s</strong>' ($BBg$-$5(B (<strong>s</strong>ize) + $B$N$"$kDL>o$N%U%!%$%k(B)<br /> + <em>TestString</em> $B$r%Q%9L>$H$7$F07$$!"$=$l$,B8:_$7$F!"(B + $B$+$DBg$-$5$,(B 0 $B$h$jBg$-$$DL>o%U%!%$%k$G$"$l$P??!#(B</li> + + <li>'<strong>-l</strong>' ($B%7%s%\%j%C%/%j%s%/(B + (symbolic <strong>l</strong>ink))<br /> + <em>TestString</em> $B$r%Q%9L>$H$7$F07$$!"$=$l$,B8:_$7$F!"(B + $B$+$D%7%s%\%j%C%/%j%s%/$G$"$l$P??!#(B</li> + + <li>'<strong>-F</strong>' ($B%5%V%j%/%(%9%H$rDL$7$?4{B8%U%!%$%k(B) + <br /> + <em>TestString</em> $B$,M-8z$J%U%!%$%k$G$"$k$3$H!"(B + $B$=$7$F$3$N%5!<%P$K$*$$$F!"8=;~E@$G@_Dj$5$l$F$$$k$9$Y$F$N(B + $B%"%/%;%9@)8f$rDL$7$F!"$=$N%Q%9L>$G%"%/%;%9$G$-$k$+$I$&$+$r(B + $B%A%'%C%/$7$^$9!#$3$l$OFbIt$N%5%V%j%/%(%9%H$r;H$C$F(B + $B%A%'%C%/$r9T$&$N$G!"Cm0U$7$F;H$o$J$$$H%5!<%P$N(B + $B%Q%U%)!<%^%s%9$rDc2<$5$;$k$3$H$K$J$j$+$M$^$;$s(B!</li> + + <li>'<strong>-U</strong>' ($B%5%V%j%/%(%9%H$rDL$7$?4{B8(B URL) + <br /> + <em>TestString</em> $B$,M-8z$J(B URL $B$G$"$k$3$H!"(B + $B$=$7$F$3$N%5!<%P$K$*$$$F!"8=;~E@$G@_Dj$5$l$F$$$k$9$Y$F$N(B + $B%"%/%;%9@)8f$rDL$7$F!"$=$N%Q%9L>$G%"%/%;%9$G$-$k$+$I$&$+$r(B + $B%A%'%C%/$7$^$9!#$3$l$OFbIt$N%5%V%j%/%(%9%H$r;H$C$F(B + $B%A%'%C%/$r9T$&$N$G!"Cm0U$7$F;H$o$J$$$H%5!<%P$N(B + $B%Q%U%)!<%^%s%9$rDc2<$5$;$k$3$H$K$J$j$+$M$^$;$s(B!</li> + </ul> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>$BCm0U(B: </strong>$B0J>e$9$Y$F$N%F%9%H$K$D$$$F!"(B + $B%(%/%9%/%i%a!<%7%g%s%^!<%/(B ('!') $B$rA0$KCV$/$3$H$K$h$j(B + $B$=$l$i$N0UL#$rH]Dj$7$?%^%C%A%s%0$r9T$J$&$3$H$,$G$-$^$9!#(B</td> + </tr> + </table> + </li> + </ol> + + <p>$B$5$i$K!"(B<code>RewriteCond</code> + $B%G%#%l%/%F%#%V$X$NBh;00z?t$H$7$F(B <em>CondPattern</em> $B$KFCJL$J(B</p> + + <blockquote> + <strong><code>[</code><em>$B%U%i%0(B</em><code>]</code></strong> + </blockquote> + $B$rDI2C$9$k$3$H$,$G$-$^$9(B + <em>$B%U%i%0(B</em>$B$O0J2<$N$b$N$r%+%s%^6h@Z$j$GJB$Y$?$b$N$G$9(B: + + <ul> + <li>'<strong><code>nocase|NC</code></strong>' + (<strong>n</strong>o <strong>c</strong>ase)<br /> + $B$3$l$OBgJ8;z>.J8;z$r6hJL$;$:$K%F%9%H$7$^$9!#(B<em>$B$9$J$o$A!"(B</em> + $BE83+$5$l$?(B<em>TestString</em> $B$H(B <em>CondPattern</em> $B$K$*$$$F!"(B + 'A-Z' $B$*$h$S(B 'a-z' $B$N4V$K$O0c$$$O$J$$$b$N$H8+$J$5$l$^$9!#(B + $B$3$N%U%i%0$O(B<em>TestString</em> $B$H(B <em>CondPattern</em> $B$N4V$N(B + $BHf3S$K$*$$$F$N$_M-8z$G$9!#%U%!%$%k%7%9%F%`>e$*$h$S%5%V%j%/%(%9%H(B + $B$N%A%'%C%/$G$O0UL#$r;}$A$^$;$s!#(B</li> + + <li> + '<strong><code>ornext|OR</code></strong>' + (<strong>or</strong> next condition)<br /> + $B%k!<%k>r7o$r7k9g$9$k$K$"$?$j!"0EL[$N(B AND $B$NBe$o$j$K%m!<%+%k$N(B + OR $B$r;H$$$^$9!#E57?E*$JNc$H$7$F!"0J2<$r;2>H$7$F$/$@$5$$!'(B + + <blockquote> +<pre> +RewriteCond %{REMOTE_HOST} ^host1.* [OR] +RewriteCond %{REMOTE_HOST} ^host2.* [OR] +RewriteCond %{REMOTE_HOST} ^host3.* +RewriteRule ...$B$3$l$i$N%[%9%H$K4X$9$kFCJL$J=hM}(B +</pre> + </blockquote> + $B$3$N%U%i%0$r;H$o$J$$>l9g$O!">r7o(B/$B%k!<%k$r(B + 3 $B2s=q$/$3$H$K$J$C$F$7$^$$$^$9!#(B + </li> + </ul> + + <p><strong>$B;HMQNc(B:</strong></p> + + <blockquote> + $B%j%/%(%9%H$NCf$N(B ``<code>User-Agent:</code>'' $B%X%C%@$K=>$C$F(B + $B%5%$%H$N%[!<%`%Z!<%8$N=q$-49$($r9T$J$&$K$O!"0J2<$N$h$&$K$7$^$9!'(B + + <blockquote> +<pre> +RewriteCond %{HTTP_USER_AGENT} ^Mozilla.* +RewriteRule ^/$ /homepage.max.html [L] + +RewriteCond %{HTTP_USER_AGENT} ^Lynx.* +RewriteRule ^/$ /homepage.min.html [L] + +RewriteRule ^/$ /homepage.std.html [L] +</pre> + </blockquote> + $B2r<a(B: $B%V%i%&%6$H$7$F(B($B<+J,<+?H$G(B 'Mozilla' $B$HL>>h$C$F$$$k(B) + $B%M%C%H%9%1!<%W%J%S%2!<%?$r;H$&>l9g!"%U%l!<%`(B<em>$B$J$I(B</em>$B$r4^$`(B + max $B$N%[!<%`%Z!<%8$r8+$k$3$H$K$J$j$^$9!#(B($BC<Kv%Y!<%9$N(B) Lynx + $B%V%i%&%6$r;H$&>l9g$O!"2hA|$d%F!<%V%k(B<em>$B$J$I(B</em>$B$r4^$^$J$$(B + min $B$N%[!<%`%Z!<%8$,I=<($5$l$^$9!#$=$l0J30$N%V%i%&%6$N>l9g$OI8=`(B + (std) $B$N%Z!<%8$,I=<($5$l$^$9!#(B + </blockquote> + <hr noshade="noshade" size="1" /> + + <h3><a id="RewriteRule" + name="RewriteRule">RewriteRule</a></h3> + <a href="directive-dict.html#Syntax" + rel="Help"><strong>$B=q<0(B:</strong></a> RewriteRule + <em>Pattern</em> <em>Substitution</em><br /> + <a href="directive-dict.html#Default" + rel="Help"><strong>$B%G%U%)%k%H(B:</strong></a> <em>$B$J$7(B</em><br /> + <a href="directive-dict.html#Context" + rel="Help"><strong>$B%3%s%F%-%9%H(B:</strong></a> $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H!"%G%#%l%/%H%j!"(B.htaccess<br /> + <a href="directive-dict.html#Override" + rel="Help"><strong>$B%*!<%P!<%i%$%I(B:</strong></a> + <em>FileInfo</em><br /> + <a href="directive-dict.html#Status" + rel="Help"><strong>$B%9%F!<%?%9(B:</strong></a> Extension<br /> + <a href="directive-dict.html#Module" + rel="Help"><strong>$B%b%8%e!<%k(B:</strong></a> mod_rewrite.c<br /> + <a href="directive-dict.html#Compatibility" + rel="Help"><strong>$B8_49@-(B:</strong></a> Apache 1.2 + (partially), Apache 1.3<br /> + + <p><code>RewriteRule</code> + $B%G%#%l%/%F%#%V$O!"<B:]$N=q$-49$($rC4Ev$7$F$/$l$kGO<VGO$G$9!#(B + $B$3$N%G%#%l%/%F%#%V$OJ#?t2s=q$/$3$H$,$G$-$^$9!#(B + $B3F%G%#%l%/%F%#%V$O0l$D$N=q$-49$(%k!<%k$rDj5A$7$^$9!#(B + $B$3$l$i%k!<%k$r(B<strong>$BDj5A$9$k=g=x(B</strong>$B$O=EMW$G$9!#(B + $B$J$<$J$i!"<B9T;~$K%k!<%k$rE,MQ$9$k:]!"$3$N=g=x$G9T$J$o$l$k$+$i$G$9!#(B + </p> + + <p><a id="patterns" name="patterns"><em>Pattern</em></a> $B$O8=:_$N(B + URL $B$KE,MQ$5$l$k(B (Apache 1.1.x $B$G$O(B System V8$B!"(BApache 1.2.x + $B0J9_$G$O(B POSIX $B$N(B)<a id="regexp" name="regexp">$B@55,I=8=(B</a>$B$G$9!#(B + $B$3$3$G!V8=:_$N!W$H8@$C$F$$$k$N$O!"%k!<%k$,E,MQ$5$l$k:]$N(B URL + $B$NCM$N$3$H$G$9!#$3$l$O%j%/%(%9%H$5$l$?%*%j%8%J%k$N(B URL + $B$G$"$k$H$O8B$j$^$;$s!#4{$K?tB?$/$N%k!<%k$,%^%C%A$7$F!"(B + $B$=$l$r=q$-49$($?8e$+$b$7$l$J$$$+$i$G$9!#(B</p> + + <p>$B@55,I=8=$NJ8K!$K4X$9$k%R%s%H(B:</p> + + <table bgcolor="#F0F0F0" cellspacing="0" cellpadding="5"> + <tr> + <td valign="top"> +<pre> +<strong>$B%F%-%9%H(B: </strong> + <strong><code>.</code></strong> $BG$0U$N0lJ8;z(B + <strong><code>[</code></strong>chars<strong><code>]</code></strong> $BJ8;z%/%i%9(B: $B$$$:$l$+$NJ8;z(B + <strong><code>[^</code></strong>chars<strong><code>]</code></strong> $BJ8;z%/%i%9(B: $B$3$l$i0J30$NJ8;z(B + text1<strong><code>|</code></strong>text2 $BA*Br;h(B: text1 $B$^$?$O(B text2 + +<strong>$BJ8;z?t;XDj(B:</strong> + <strong><code>?</code></strong> $BD>A0$NJ8;z$N(B 0 $B2s$^$?$O(B 1 $B2s$N7+$jJV$7(B + <strong><code>*</code></strong> $BD>A0$NJ8;z$N(B 0 $B2s0J>e$N7+$jJV$7(B + <strong><code>+</code></strong> $BD>A0$NJ8;z$N(B 1 $B2s0J>e$N7+$jJV$7(B + +<strong>$B%0%k!<%T%s%0(B:</strong> + <strong><code>(</code></strong>text<strong><code>)</code></strong> $B%F%-%9%H$N%0%k!<%T%s%0(B + ($BA*Br;h$N6-3&$rL@<($9$k!"<c$7$/$O8eJ};2>H$r:n@.$9$k$?$a$K;H$&!#(B + <strong>N</strong>$BHVL\$N%0%k!<%W$O!"(BRewriteRule $B$N1&B&$NI=8=$G(B<code>$</code><strong>N</strong>$B$H$7$F;2>H$9$k$3$H$,2DG=!#!K(B + +<strong>$BJ8;z0LCV$N;XDj(B:</strong> + <strong><code>^</code></strong> $B9TF,(B + <strong><code>$</code></strong> $B9TKv(B + +<strong>$B%(%9%1!<%W(B:</strong> + <strong><code>\</code></strong>char $BFC<lJ8;z$r%(%9%1!<%W(B($B8z2L$rBG$A>C$9(B)$B$9$k(B + ($BNc$($P(B "<code>.[]()</code>" <em>$B$J$I(B</em>) +</pre> + </td> + </tr> + </table> + + <p>$B@55,I=8=$K4X$9$k>pJs$O!"%m!<%+%k$N(B regex(3) man $B%Z!<%8$+$^$?$O(B + Apache 1.3 $B$NG[I[J*$K4^$^$l$k(B<code>src/regex/regex.3</code> + $B$r;2>H$7$F$/$@$5$$!#$b$7@55,I=8=$d$=$NJQ<o(B (POSIX $B@55,I=8=!"(B + Perl $B@55,I=8=(B <em>$B$J$I(B</em>)$B$K6=L#$,$"$l$P!"0J2<$N@lLg=q$r$4Mw2<$5$$(B:</p> + + <blockquote> + <em>Mastering Regular Expressions</em><br /> + Jeffrey E.F. Friedl<br /> + Nutshell Handbook Series<br /> + O'Reilly & Associates, Inc. 1997<br /> + ISBN 1-56592-257-3<br /> + </blockquote> + + <p>($BLuCm(B: $BBh(B2$BHG$NF|K\8lHG(B)</p> + + <blockquote> + <em>$B>\@b(B $B@55,I=8=(B $BBh(B2$BHG(B</em><br /> + Jeffrey E. F. Friedl $BCx(B<br /> + $BEDOB(B $B>!(B $BLu(B<br /> + $B%*%i%$%j!<!&%8%c%Q%s(B 2003<br /> + ISBN 4-87311-130-7<br /> + </blockquote> + + <p>$B$5$i$K!"(Bmod_rewrite $B$G$O%Q%?!<%s$NA0$K(B NOT $BJ8;z(B('<code>!</code>') + $B$,;H$($^$9!#$3$l$G8eB3$N%Q%?!<%s$rH]Dj$9$k$3$H$,$G$-$^$9!#(B + $BNc$($F$$$&$J$i$P!"(B``<em>$B$b$78=:_$N(B URL + $B$,$3$N%Q%?!<%s$K%^%C%A(B<strong>$B$7$J$1$l$P(B</strong></em>'' + $B$H$$$&$3$H$G$9!#$3$l$O!"H?BP$N%Q%?!<%s$rI=$9J}$,4JC1$@$C$?$j!"(B + $B:G8e$N%G%U%)%k%H%k!<%k$H$9$k$J$I!"(B + $BNc30E*$J%1!<%9$rI=8=$9$k$N$K$b;H$($^$9!#(B</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>$BCm0U(B:</strong> NOT + $BJ8;z$r;H$C$F%Q%?!<%s$rH]Dj$9$k>l9g$O%Q%?!<%sCf$K(B + $B%0%k!<%W2=$5$l$?%o%$%k%I%+!<%IItJ,$rF~$l$k$3$H$O$G$-$^$;$s!#(B + $B$3$l$O!"%Q%?!<%s$,%^%C%A(B *$B$7$J$$(B* $B$H$-!"(B + $B%0%k!<%W$NCf?H$O6u$K$J$C$F$7$^$&$+$i$G$9!#$=$N7k2L!"(B + $BH]Dj$5$l$?%Q%?!<%s$r;H$&>l9g$O!"CV$-49$(J8;zNs$NCf$G(B + <code>$N</code> $B$O;H$($^$;$s(B!</td> + </tr> + </table> + + <p>$B=q$-49$(%k!<%k$N(B <a id="rhs" + name="rhs"><em>Substitution</em></a> $B$O!"(B<em>Pattern</em>$B$,(B + $B%^%C%A$7$?>l9g$K%*%j%8%J%k$N(B URL $B$+$iCV$-49$($i$l$kJ8;zNs$G$9!#(B + $B%W%l!<%s%F%-%9%H$NB>$K0J2<$N$b$N$,;H$($^$9!#(B</p> + + <ol> + <li>RewriteRule $B%Q%?!<%s$X$N8eJ};2>H(B <code>$N</code></li> + + <li>$B:G8e$K%^%C%A$7$?(B RewriteCond $B%Q%?!<%s$X$N8eJ};2>H(B + <code>%N</code></li> + + <li>$B%k!<%k>r7o$N%F%9%HJ8;zNs$HF1MM$N%5!<%PJQ?t(B + (<code>%{$BJQ?tL>(B}</code>)</li> + + <li><a href="#mapfunc">$B%^%C%T%s%04X?t(B</a> $B$N8F$S=P$7(B + (<code>${mapname:key|default}</code>)</li> + </ol> + $B8eJ};2>H$O(B <code>$</code><strong>N</strong>(<strong>N</strong>=0..9) + $B<1JL;R$GI=$7$^$9!#$3$l$O!"%^%C%A$7$?(B <em>Pattern</em> $B$N%0%k!<%W$NCf$G!"(B + <strong>N</strong> $BHVL\$N$b$N$NFbMF$KCV$-49$($i$l$^$9!#%5!<%PJQ?t$O(B + <code>RewriteCond</code> $B%G%#%l%/%F%#%V$N(B <em>TestString</em> $B$HF1$8$G$9!#(B + $B%^%C%T%s%04X?t$O(B <code>RewriteMap</code> $B%G%#%l%/%F%#%V$+$iMh$?$b$N$G!"(B + $B$=$3$G@bL@$7$F$$$^$9!#$3$l$i(B 3 $B%?%$%W$NJQ?t$O!">e5-$N=g=x$GE83+$5$l$^$9!#(B + + <p>$BA0=R$N$h$&$K!"$9$Y$F$N=q$-49$(%k!<%k$,(B <em>Substitution</em> $B$KBP$7$F(B + ($B@_Dj%U%!%$%k$KDj5A$7$F$"$k=g$K(B)$BE,MQ$5$l$^$9!#(BURL + $B$O(B <em>Substitution</em> $B$K$h$C$F(B<strong>$B40A4$KCV$-49$($i$l(B</strong>$B!"(B + $B=q$-49$(=hM}$O(B <code><strong>L</strong></code> $B%U%i%0(B -- $B8e=R(B -- + $B$K$h$C$FL@<(E*$K=*C<$5$l$F$$$J$$8B$j!"(B + $B%k!<%k$,$J$/$J$k$^$GB3$1$i$l$^$9!#(B</p> + + <p>'<code>-</code>' $B$H8F$P$l$kFC<l$JCV$-49$(J8;zNs$,$"$j$^$9!#(B + $B$3$l$O!"(B<strong>$BCV496X;_(B</strong>! $B$N0UL#$G$9!#JQ$G$7$g(B? + $B$$$$$(!"$3$l$O(B URL $B$N%^%C%A%s%0(B<strong>$B$@$1(B</strong>$B$r9T$J$$!"(B + $BCV49$r9T$J$o$J$$$H$$$&5!G=$rDs6!$7$F$/$l$k$b$N$G$9!#(B + <em>$B$9$J$o$A(B</em>$B!"(B<strong>C</strong> (chain) + $B%U%i%0$H$J$$$C$7$g$K;H$&$3$H$K$h$C$F!"(B + $BCV49$,9T$J$o$l$kA0$KJ#?t$N%Q%?!<%s$rE,MQ$9$k$3$H$,$G$-$^$9!#(B</p> + + <p>$B$b$&$R$H$DCm0U;v9`(B: $B%/%(%j!<J8;zNsItJ,$rIU2C$7$?CV49J8;zNs$G(B + URL $B$r@8@.$9$k$3$H$b$G$-$^$9!#(B + $BC1$K!"CV49J8;zNs$NCf$K%/%(%9%A%g%s%^!<%/$rF~$l$k$@$1$G!"$=$l0J9_$O(B + QUERY_STRING $B$KF~$l$k$Y$-$3$H$r<($7$^$9!#(B + $B4{B8$N%/%(%j!<J8;zNs$r>C5n$7$?$$>l9g$O!"(B + $BCV49J8;zNs$r%/%(%9%A%g%s%^!<%/$@$1$G=*$o$i$;$k$h$&$K$7$^$9!#(B</p> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>$BCm0U(B</strong>: $BFC<l5!G=$K$D$$$F=R$Y$^$9(B: + $BCV49%U%#!<%k%I$NA0$K(B + <code>http://</code><em>thishost</em>[<em>:thisport</em>] + $B$rCV$/$H!"(B<strong>mod_rewrite</strong> + $B$O<+F0E*$K$3$l$r=|5n$7$^$9!#$3$N0EL[$N30It%j%@%$%l%/%H(B URL + $B$K$*$1$k<+F0JQ495!G=$O!"%[%9%HL>ItJ,$r@8@.$9$k(B + $B%^%C%T%s%04X?t$HF1;~$K;H$&>l9g$KJXMx$+$D=EMW$J$b$N$G$9!#(B + $B$3$l$rM}2r$9$k$K$O!"0J2<$N%5%s%W%k$N>O$N:G=i$NNc$r8+$F$/$@$5$$!#(B + </td> + </tr> + </table> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>$BHw9M(B: $B$3$N5!G=$N1F6A$G!"(B</strong> + <code>http://thishost</code> $B@\F,<-$NIU$$$?(B + $B<+J,<+?H$N%5!<%P$X$NL5>r7o$N30It%j%@%$%l%/%7%g%s$O!"(B + $BF0:n$7$^$;$s!#(B + $B$3$N$h$&$J<+8J%j%@%$%l%/%H$r9T$&$K$O!"(B<strong>R</strong> + $B%U%i%0$r;H$&I,MW$,$"$j$^$9(B($B8e=R(B)$B!#(B</td> + </tr> + </table> + + <p><code>RewriteRule</code> $B%G%#%l%/%F%#%V$NBh;00z?t$H$7$F!"(B + <em>Pattern</em> $B$KBP$7$F>e5-0J30$K$b0J2<$N$h$&$J(B</p> + + <blockquote> + <strong><code>[</code><em>$B%U%i%0(B</em><code>]</code></strong> + </blockquote> + $B$r$D$1$k$3$H$,$G$-$^$9!#(B + <em>$B%U%i%0(B</em>$B$O0J2<$N$b$N$r%+%s%^$G6h@Z$C$F;XDj$7$^$9(B: + + <ul> + <li> + '<strong><code>redirect|R</code> + [=<em>code</em>]</strong>' ($B6/@)(B <a id="redirect" + name="redirect"><strong>r</strong>edirect</a>)<br /> + + <em>Substitution</em> $B$NA0$K(B ($B?7$7$$(B URL $B$r(B URI $B$K$9$k(B) + <code>http://thishost[:thisport]/</code> + $B$r$D$1$k$3$H$K$h$j6/@)E*$J30It%j%@%$%l%/%7%g%s$r9T$J$$$^$9!#(B + <em>code</em> $B$,;XDj$5$l$J$$>l9g!"(BHTTP $B%l%9%]%s%9$N(B 302 + (MOVED TEMPORARILY) $B$,;H$o$l$^$9!#(B300 $B$+$i(B 400 + $B$^$G$NB>$N%l%9%]%s%9%3!<%I$rJV$7$?$$>l9g$O!"(B + $BD>@\$=$NHV9f$r;XDj$9$k$+!"%7%s%\%kL>(B <code>temp</code> + ($B%G%U%)%k%H(B), <code>permanent</code>, <code>seeother</code> + $B$N$$$:$l$+$r;H$$$^$9!#(B<em>$BNc$($P(B</em>$B!"(B``<code>/~</code>'' + $B$r(B ``<code>/u/</code>'' $B$KJQ49$7$?$j!">o$K(B <code>/u/</code> + <em>user</em> $B$K%9%i%C%7%e$rDI2C$9$k$J$I$N!"%/%i%$%"%s%H$K(B $B@55,2=(B + $B$5$l$?(B URL $B$rJV$9%k!<%k$K;H$&$3$H$,$G$-$^$9!#(B<br /> + + <p><strong>$BCm0U(B:</strong> + $B$3$N%U%i%0$r;H$&>l9g$O!"CV49%U%#!<%k%I$,M-8z$J(B URL + $B$G$"$k$3$H$r3NG'$7$F$/$@$5$$!#$b$7$=$&$G$J$$>l9g!"(B + $BL58z$J>l=j$K%j%@%$%l%/%H$7$F$$$k$3$H$K$J$C$F$7$^$$$^$9!#(B + $B$5$i$K!"$3$N%U%i%0$O!"(BURL $B$NA0$K(B + <code>http://thishost[:thisport]/</code> + $B$rIU2C$9$k$@$1$G!"$=$N8e$b=q$-49$(=hM}$OB3$/$3$H$r(B + $BM}2r$7$F$*$$$F$/$@$5$$!#(B + $BDL>o$O$=$3$G=q$-49$($r$d$a$FB(;~$K%j%@%$%l%/%H$9$k$3$H$,K>$_$NF0:n(B + $B$G$7$g$&!#(B + $B=q$-49$($r=*N;$9$k$K$O!"(B + 'L' $B%U%i%0$b$$$C$7$g$K;XDj$7$J$1$l$P$J$j$^$;$s!#(B</p> + </li> + + <li>'<strong><code>forbidden|F</code></strong>' (URL $B$r6/@)E*$K(B + <strong>f</strong>orbidden($B6X;_(B)$B$K$9$k(B)<br /> + $B$3$l$O8=:_$N(B URL $B$r6/@)E*$K%"%/%;%96X;_$K$7$^$9!#(B + <em>$B$9$J$o$A(B</em>$B!"B(;~$K(B HTTP $B%l%9%]%s%9$N(B 403 (FORBIDDEN) + $B$rJV$7$^$9!#$3$N%U%i%0$OE,@Z$J(B RewriteCond + $B$H$$$C$7$g$K;H$C$F!"FCDj$N(B URL $B$KBP$9$k>r7o%V%m%C%/$r9T$J$&$?$a$K(B + $B;H$$$^$9!#(B</li> + + <li>'<strong><code>gone|G</code></strong>' (URL $B$r6/@)E*$K(B + <strong>g</strong>one($B>C5n:Q$_(B)$B$K$9$k(B)<br /> + $B$3$l$O8=:_$N(B URL $B$r6/@)E*$K>C5n:Q$_(B(gone)$B$K$7$^$9!#(B + <em>$B$9$J$o$A(B</em>$B!"B(;~$K(B HTTP $B%l%9%]%s%9$N(B 410 (GONE) + $B$rJV$7$^$9!#$3$N%U%i%0$O$b$O$dB8:_$7$J$$%Z!<%8$r(B + $B>C5n:Q$_$H$7$F%^!<%/$9$k$?$a$K;H$$$^$9!#(B</li> + + <li> + '<strong><code>proxy|P</code></strong>' ($B6/@)(B + <strong>p</strong>roxy)<br /> + $B$3$N%U%i%0$O!"CV49BP>]It$rFbItE*$J%W%m%-%7%j%/%(%9%H(B + $B$H$_$J$7!"$=$N>l$G(B(<em>$B$9$J$o$A(B</em>$B!"(B + $B$3$3$G=q$-49$(%k!<%k$rDd;_$7$F(B)<a + href="mod_proxy.html">$B%W%m%-%7%b%8%e!<%k$r(B</a>$BDL$7$F=PNO$7$^$9!#(B + $BCV49BP>]J8;zNs$O(B(<em>$BNc$($P(B</em>$B!"IaDL$O(B <code>http://</code> + <em>hostname</em>$B$G;O$^$k$h$&$J(B)$B!"(BApache + $B%W%m%-%7%b%8%e!<%k$G07$($kM-8z$J(B URI $B$G$J$1$l$P$J$j$^$;$s!#(B + $B$=$&$G$J$1$l$P!"%W%m%-%7%b%8%e!<%k$+$i%(%i!<$,Js9p$5$l$^$9!#(B + $B$3$N%U%i%0$r;H$&$3$H$G$h$j6/NO$J(B <a + href="mod_proxy.html#proxypass">ProxyPass</a> + $B%G%#%l%/%F%#%V$N<BAu$r9T$J$&$3$H$,$G$-!"%j%b!<%H$K$"$k$b$N$r(B + $B%m!<%+%k%5!<%P$NL>A06u4V$K%^%C%W$9$k$3$H$,$G$-$^$9!#(B + + <p>$BCm0U(B: $B$3$N5!G=$r;H$&$K$"$?$C$F$O!"$4<+J,$N(B Apache $B%5!<%P$K(B + $B%W%m%-%7%b%8%e!<%k$,AH$_9~$^$l$F$$$k$3$H$r(B + $B3NG'$7$F$/$@$5$$!#3NG'J}K!$,$o$+$i$J$$>l9g$O!"(B``<code>httpd + -l</code>'' $B$N=PNO$NCf$K(B <code>mod_proxy.c</code> + $B$,$"$k$+$I$&$+$rD4$Y$F$_$^$7$g$&!#$b$7$"$l$P!"(B + mod_rewrite $B$N$3$N5!G=$r;H$($^$9!#$b$7$J$1$l$P!"(Bmod_proxy + $B$rM-8z$K$7$F(B ``<code>httpd</code>'' + $B%W%m%0%i%`$r:F9=C[$9$kI,MW$,$"$j$^$9!#(B</p> + </li> + + <li>'<strong><code>last|L</code></strong>' + (<strong>l</strong>ast($B:G8e$N(B)$B%k!<%k(B)<br /> + $B$3$3$G=q$-49$(=hM}$rCf;_$7!"(B + $B$=$l0J>e$N=q$-49$(%k!<%k$rE,MQ$7$J$$$h$&$K$7$^$9!#$3$l$O(B Perl + $B$N(B <code>last</code> $B%3%^%s%I$d(B C $B8@8l$N(B <code>break</code> + $B%3%^%s%I$KBP1~$9$k$b$N$G$9!#$3$N%U%i%0$r;H$&$3$H$G!"(B + $B8=:_$N=q$-49$(8e$N(B URL $B$,8eB3$N%k!<%k$K$h$C$F(B + $B$=$l0J>e=q$-49$($i$l$k$3$H$rKI;_$7$^$9!#(B + $BNc$($P!"$3$l$r;H$C$F%k!<%H%Q%9$N(B URL ('<code>/</code>') + $B$r<B:]$N$b$N!"(B<em>$BNc$($P(B </em>'<code>/e/www/</code>' + $B$K=q$-49$($^$9!#(B</li> + + <li>'<strong><code>next|N</code></strong>' + (<strong>n</strong>ext($B<!$N(B)$B0l<~(B)<br /> + $B=q$-49$(=hM}$r(B($B0lHV:G=i$N=q$-49$(%k!<%k$+$i(B)$B:F<B9T$7$^$9!#(B + $B$?$@$7$=$N:]%^%C%A%s%0$5$l$k(B URL $B$OEv=i$N(B URL + $B$G$O$J$/!":G8e$K=q$-49$($i$l$?(B URL $B$G$9!#$3$l$O(B Perl + $B$N(B <code>next</code> $B%3%^%s%I$d(B C $B8@8l$N(B <code>continue</code> + $B%3%^%s%I$KBP1~$9$k$b$N$G$9!#(B + $B=q$-49$(=hM}$r:F5/F0$7$?$$$H$-(B + <em>$B$9$J$o$A!"(B</em>$B%k!<%W$N@hF,$KLa$j$?$$$H$-(B<br />$B$K(B + $B$3$N%3%^%s%I$r;H$C$F$/$@$5$$!#(B + <strong>$B$?$@$7!"L58B%k!<%W$r:n$i$J$$$h$&$KN10U$7$F$/$@$5$$(B! + </strong></li> + + <li>'<strong><code>chain|C</code></strong>' + ($B<!$N%k!<%k$K(B <strong>c</strong>hained ($B%A%'%$%s(B))<br /> + $B$3$N%U%i%0$r;XDj$9$k$H!"8=:_$N%k!<%k$O<!$N%k!<%k$K%A%'%$%s$5$l$^$9(B + ($B$J$*!"<!$N%k!<%k$b8eB3$N%k!<%k$K=gHV$K(B + $B%A%'%$%s$9$k$3$H$,$G$-$^$9(B)$B!#$3$l$K$O0J2<$N8z2L$,$"$j$^$9(B: + $B%k!<%k$,%^%C%A$9$k$H!"=hM}$ODL>o$I$*$j9T$o$l$^$9!#(B + <em>$B$9$J$o$A(B</em>$B%U%i%0$O2?$N1F6A$bM?$($^$;$s!#%k!<%k$,%^%C%A(B + <strong>$B$7$J$$(B</strong>$B>l9g!"8eB3$N$9$Y$F$N%k!<%k$O%9%-%C%W$5$l$^$9!#(B + $BNc$($P(B (.www $BItJ,$,9T$J$o$l$k$Y$-$G$J$$(B) + $B30It%j%@%$%l%/%H$rH/@8$5$;$?;~$K!"(B + $B%G%#%l%/%H%j$4$H$N%k!<%k%;%C%H$NCf$+$i(B ``<code>.www</code>'' + $B$NItJ,$r<h$j=|$/$?$a$K;H$&$3$H$G$-$^$9!#(B + </li> + + <li> + '<strong><code>type|T</code></strong>=<em>MIME-type</em>' + (MIME <strong>t</strong>ype $B$N6/@);XDj(B)<br /> + $B%?!<%2%C%H%U%!%$%k$N(B MIME $B%?%$%W$r6/@)E*$K(B <em>MIME-type</em> + $B$K$7$^$9!#Nc$($P$3$l$r;H$C$F!"(B<code>mod_alias</code> + $B$N%G%#%l%/%F%#%V$G$"$k(B <code>ScriptAlias</code> + $B$r%7%_%e%l!<%H$9$k$3$H$,$G$-$^$9!#$3$l$O!"(B + $B%^%C%T%s%0$5$l$?%G%#%l%/%H%j$NCf$K$"$k$9$Y$F$N%U%!%$%k$N(B MIME + $B%?%$%W$r!"FbItE*$K(B``<code>application/x-httpd-cgi</code>'' + $B$K6/@)%;%C%H$9$k$b$N$G$9!#(B</li> + + <li> + '<strong><code>nosubreq|NS</code></strong>' (<strong>n</strong>o + <strong>s</strong>ub-request, + $BFbIt$N(B + $B%5%V%j%/%(%9%H$,$J$$(B + $B$H$-$N$_;H$o$l$k(B)<br /> + $B$3$N%U%i%0$r;H$&$H!"%/%(%9%H$,FbIt$N%5%V%j%/%(%9%H$G$"$k>l9g$K!"(B + $B=q$-49$(%(%s%8%s$,=q$-49$(%k!<%k$r%9%-%C%W$9$k$h$&$K$7$^$9!#(B + $B%5%V%j%/%(%9%H$O!"Nc$($P!"(B<code>mod_include</code> + $B$,%G%#%l%/%H%j$N%G%U%)%k%H$N8uJd$H$J$k%U%!%$%k$N>pJs(B + (<code>index.xxx</code>) $B$r8!:w$7$h$&$H$9$k:]$K!"(BApache + $B$NCf$GFbItE*$KH/@8$7$^$9!#(B + $B%5%V%j%/%(%9%H$K$*$$$F$O=q$-49$(A`:n$O>o$KM-MQ$G$"$k$H$O8B$i$:!"(B + $B$9$Y$F$N%k!<%k$,E,MQ$5$l$F$7$^$&$HLdBj$r5/$3$7$F$7$^$&>l9g$b$"$j$^$9!#(B + $B$=$N$h$&$J%k!<%k$O$3$N%U%i%0$r;H$C$F=|30$7$^$9!#(B<br /> + + <p>$B0J2<$N%k!<%k$r;H$C$F!"$3$N%U%i%0$r;H$&$+$I$&$+7h$a$F$/$@$5$$(B: + CGI $B%9%/%j%W%H$N@hF,$K$J$s$i$+$N(B URL $B$rIU2C$7$F!"$=$l$r(B CGI + $B%9%/%j%W%H$G=hM}$5$;$h$&$H$9$k>l9g!"%5%V%j%/%(%9%H$N:]$KLdBj$,(B + $B5/$3$C$?$j(B ($B%*!<%P!<%X%C%I$,$+$+$C$?$j(B) $B$9$k2DG=@-$,9b$/$J$j$^$9!#(B + $B$3$N$h$&$J%1!<%9$G$O!"$3$N%U%i%0$r;H$C$F$/$@$5$$!#(B</p> + </li> + + <li>'<strong><code>nocase|NC</code></strong>' + (<strong>n</strong>o <strong>c</strong>ase)<br /> + $B$3$l$O(B<em>$B%Q%?!<%s(B</em>$B$K$D$$$FBgJ8;z>.J8;z$r6hJL$7$J$$$h$&$K$7$^$9!#(B + <em>$B$9$J$o$A(B</em>$B!"(B<em>$B%Q%?!<%s(B</em>$B$,8=:_$N(B URL $B$H%^%C%A$5$l$k:]!"(B + 'A-Z' $B$H(B 'a-z' $B$O6hJL$5$l$^$;$s!#(B</li> + + <li>'<strong><code>qsappend|QSA</code></strong>' + (<strong>q</strong>uery <strong>s</strong>tring + <strong>a</strong>ppend)<br /> + $B$3$N%U%i%0$O!"4{B8$N$b$N$rCV$-49$($k$N$G$O$J$/!"CV49J8;zNs$N(B + $B%/%(%j!<J8;zNsItJ,$rDI2C$9$k$h$&$K$7$^$9!#=q$-49$(%k!<%k$rDL$7$F%/%(%j!<(B + $BJ8;zNs$K2?$+%G!<%?$rDI2C$7$?$$>l9g$K$3$N%U%i%0$r;H$$$^$9!#(B</li> + + <li> + '<strong><code>noescape|NE</code></strong>' + (<strong>n</strong>o URI <strong>e</strong>scaping of + output)<br /> + $B$3$N%U%i%0$O!"(Bmod_rewrite $B$,=q$-49$(7k2L$KBP$7$FDL>o9T$J$o$l$k(B + URL $B%(%9%1!<%W%k!<%k$rE,MQ$7$J$$$h$&$K$7$^$9!#DL>o$O(B ('%', + '$', ';' $B$H$$$C$?(B) $BFC<lJ8;z$K$D$$$F$O!"$=$l$i$HEy2A$N(B 16 + $B?J?tJ8;zNs(B ($B=g$K(B '%25', '%24', '%3B') $B$K%(%9%1!<%W$5$l$^$9!#(B + $B$3$N%U%i%0$O$3$NF0:n$rM^@)$7$^$9!#(B + $B$3$l$K$h$j!"=PNO$NCf$K%Q!<%;%s%HJ8;z$r;H$&$3$H$,$G$-$^$9!#(B + $B0J2<$KNc$r5s$2$^$9!#(B +<pre> + RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE] + +</pre> + $B$3$NNc$G$O!"(B'<code>/foo/zed</code>' $B$,0BA4$J%j%/%(%9%H$G$"$k(B + '<code>/bar?arg=P1=zed</code>' $B$KJQ99$5$l$^$9!#(B + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>$BCm0U(B:</strong> + <code>noescape</code> $B%U%i%0$O(B Apache 1.3.20 + $B0J9_$G$N$_M-8z$G$9!#(B</td> + </tr> + </table> + </li> + + <li> + '<strong><code>passthrough|PT</code></strong>' + (<strong>p</strong>ass <strong>t</strong>hrough to next + handler)<br /> + $B$3$N%U%i%0$O!"FbIt$N(B <code>request_rec</code> $B9=B$BN$N(B + <code>uri</code> $B%U%#!<%k%I$K(B <code>filename</code> + $B%U%#!<%k%I$NCM$r%;%C%H$9$k$h$&$K!"=q$-49$(%(%s%8%s$K;X<($7$^$9!#(B + $B$3$N%U%i%0$OC1$K!"(B<code>RewriteRule</code> + $B%G%#%l%/%F%#%V$N=PNO$KBP$7$F!"B>$N(B URI + $B$+$i%U%!%$%kL>$X$NJQ49=hM}$r9T$&(B <code>Alias</code>, + <code>ScriptAlias</code>, <code>Redirect</code> + <em>$B$H$$$C$?(B</em>$B%G%#%l%/%F%#%V$K$h$k8e=hM}$rF~$l$k$?$a$N>.5;$G$9!#(B + $B0UL#$r<($9$?$a$NC1=c$JNc(B: <code>mod_rewrite</code> + $B$N=q$-49$(%(%s%8%s$G(B <code>/abc</code> $B$+$i(B <code>/def</code> + $B$X$NJQ49$r9T$J$$!"$5$i$K(B <code>mod_alias</code> $B$G(B + <code>/def</code> $B$+$i(B <code>/ghi</code> + $B$K=q$-49$($k$K$O!"0J2<$N$h$&$K$7$^$9(B: +<pre> + RewriteRule ^/abc(.*) /def$1 [PT] + Alias /def /ghi + +</pre> + $B$b$7(B <code>PT</code> $B%U%i%0$r;XDj$9$k$N$rK:$l$F$7$^$C$?>l9g!"(B + <code>mod_rewrite</code> $B$O$A$c$s$H$=$N;E;v$r9T$J$$$^$9!#(B + <em>$B$9$J$o$A(B</em>$B!"40A4$J(B API $B$K=`5r$7$?(B URI-to-filename + $BJQ49%k!<%A%s$,9T$&$Y$-!"(B<code>uri=/abc/...</code> $B$r(B + <code>filename=/def/...</code> $B$K=q$-49$(!"$r9T$J$$$^$9!#$=$N8e(B + <code>mod_alias</code> $B$,5/F0$5$l!"(BURI-to-filename + $BJQ49$r;n$_$^$9$,!"$3$l$OF0:n$7$^$;$s(B $B!#(B + + <p>$BCm0U(B: <strong>URL-to-filename + $BJQ49$r4^$`0[$J$C$?%b%8%e!<%k$N%G%#%l%/%F%#%V$r:.MQ$7$?$$>l9g$K$O!"(B + $B$3$N%U%i%0$r;XDj$9$kI,MW$,$"$j$^$9!#(B</strong>$BE57?E*$JNc$H$7$F$O!"(B + <code>mod_alias</code> $B$H(B <code>mod_rewrite</code> + $B$NF1;~;HMQ$G$9!#(B</p> + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><font size="-1"><strong>$BCm0U(B - Apache $B%O%C%+!<$X(B: + </strong><br /> + $B8=:_$N(B Apache API $B$K(B URI-to-filename $B%U%C%/$K2C$($F(B + filename-to-filename $B%U%C%/$,$"$l$P!"(B + $B$3$N%U%i%0$r;H$&I,MW$O$J$$$N$G$9(B! + $B$7$+$7$3$N$h$&$J%U%C%/$,$J$$8=:_!"(B + $B$3$N%U%i%0$,M#0l$N2r7h:v$H$J$j$^$9!#(BApache + $B%0%k!<%W$O$3$NLdBj$K$D$$$F5DO@$7$F$*$j!"(BApache $B%P!<%8%g%s(B + 2.0 $B$K$O$=$N$h$&$J%U%C%/$,DI2C$5$l$k$3$H$G$7$g$&!#(B</font> </td> + </tr> + </table> + </li> + + <li>'<strong><code>skip|S</code></strong>=<em>num</em>' + (<strong>s</strong>kip next rule(s))<br /> + $B$3$N%U%i%0$O=q$-49$(%(%s%8%s$KBP$7!"8=:_$N%k!<%k$,%^%C%A$7$?$i!"(B + $B<!$N(B <em>num</em> $B8D$N%k!<%k$r%9%-%C%W$9$k$h$&;X<($7$^$9!#$3$l$r(B + $B;H$C$F!"5<;wE*$K(B if-then-else $B9=B$$r:n$k$3$H$,$G$-$^$9(B: then-$B6g(B + $B$N:G=*%k!<%k$O(B <code>skip=N</code> $B$H$J$j$^$9!#$3$3$G(B N $B$O(B + else-$B6g(B $B$KF~$l$k%k!<%k$N?t$G$9!#(B($B$3$l$O(B 'chain|C' $B%U%i%0$H$O(B + <strong>$B0[$J$j$^$9(B</strong>!)$B!#(B</li> + + <li> + '<strong><code>env|E=</code></strong><em>VAR</em>:<em>VAL</em>' + (set <strong>e</strong>nvironment variable)<br /> + $B$3$l$O(B <em>VAR</em> $B$H$$$&L>A0$N4D6-JQ?t$NCM$r(B <em>VAL</em> + $B$K$9$k$h$&;X<($7$^$9!#$3$3$G(B <em>VAL</em> + $B$K$O!"@55,I=8=$N8eJ};2>H$H$7$FE83+$5$l$k(B <code>$N</code> $B$H(B + <code>%N</code> $B$r=q$/$3$H$,$G$-$^$9!#(B + $B$3$N%U%i%0$rJ#?t;H$C$F!"J#?t$NJQ?t$rDj5A$9$k$3$H$b$G$-$^$9!#(B + $B$3$NJQ?t$OB?$/$N>l9g!"DL>o8e$+$i(B XSSI (<code><!--#echo + var="VAR"--></code> $B$rDL$7$F(B) $B$^$?$O(B CGI (<em>$BNc$($P(B</em> + <code>$ENV{'VAR'}</code>) $B$N$h$&$K!";2>H$5$l$^$9!#$5$i$K!"(B + RewriteCond $B%Q%?!<%s(B <code>%{ENV:VAR}</code> + $B$rDL$7$F;2>H$9$k$3$H$b$G$-$^$9!#$3$l$r;H$C$F(B URL + $B$+$i$N>pJs$r@Z$j<h$C$F5-21$7$^$9!#(B</li> + </ul> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td> + <strong>$BCm0U(B:</strong> + $B%5!<%PC10L$N@_Dj%U%!%$%k$NCf$G$O!"(B<em>Pattern</em> $B$O40A4$J(B + URL $B$KE,MQ$5$l$k$3$H$rK:$l$J$$$G$/$@$5$$!#(B + <strong>$B$7$+$7$J$,$i!"%G%#%l%/%H%jC10L$N@_Dj%U%!%$%k$NCf$G$O!"(B + $B%Q%?!<%s%^%C%A%s%0$N$?$a$K%G%#%l%/%H%jC10L$N@\F,<-(B + ($B$3$l$OFCDj$N%G%#%l%/%H%j$G$O>o$KF1$8$b$N$G$9(B!) $B$,<+F0E*$K(B + <em>$B<h$j=|$+$l(B</em>$B!"CV49$,=*$o$C$?8e$K<+F0E*$K(B<em>$BIU2C(B</em> + $B$5$l$^$9!#(B</strong>$B$3$N5!9=$O!"$5$^$6$^$J<oN`$N=q$-49$(A`:n$K(B + $B$*$$$F7g$/$3$H$N$G$-$J$$$b$N$G$9!#$J$<$J$i!"$3$N@\F,<-$N%9%-%C%W(B + $B$,9T$J$o$l$J$$$H!">o$KB8:_$9$k$H$O8B$i$J$$?F%G%#%l%/%H%j$H$N(B + $B%^%C%A%s%0$r9T$J$o$J$1$l$P$J$i$J$/$J$k$+$i$G$9!#(B + + <p>$B$R$H$DNc30$,$"$j$^$9(B: $BCV49J8;zNs$,(B ``<code>http://</code>'' + $B$G;O$^$C$F$$$k>l9g!"%G%#%l%/%H%j@\F,<-$OIU2C(B<strong>$B$5$l$:(B + </strong>$B!"30It%j%@%$%l%/%H$^$?$O(B (<strong>P</strong> $B%U%i%0$,(B + $B;H$o$l$F$$$l$P(B!) $B%W%m%-%7=hM}$,6/@)E*$K9T$J$o$l$^$9!#(B</p> + </td> + </tr> + </table> + + <table width="70%" border="0" bgcolor="#E0E0F0" + cellspacing="0" cellpadding="10"> + <tr> + <td><strong>$BCm0U(B:</strong> $B%G%#%l%/%H%jC10L$N@_Dj%U%!%$%k(B + $B$K$*$1$k=q$-49$(%(%s%8%s$rM-8z$K$9$k>l9g!"$3$l$i$N%U%!%$%k$K(B + ``<code>RewriteEngine On</code>'' $B$r%;%C%H$7!"(B<strong>$B$+$D(B + </strong>``<code>Options FollowSymLinks</code>'' $B$rM-8z$K(B + $B$7$J$1$l$P$J$j$^$;$s!#$"$J$?$N$H$3$m$N4IM}<T$,%f!<%6$N(B + $B%G%#%l%/%H%j$N(B <code>FollowSymLinks</code> $B$N%*!<%P!<%i%$%I(B + $B$r6X;_$7$F$$$?>l9g!"=q$-49$(%(%s%8%s$r;H$&$3$H$O$G$-$^$;$s!#(B + $B$3$N@)8B$,I,MW$J$N$O!"%;%-%e%j%F%#4XO"$NM}M3$K$h$j$^$9!#(B</td> + </tr> + </table> + + <p>$B0J2<$KM-8z$JCV49$NAH9g$;$H!"$=$l$i$N0UL#$r<($7$^$9(B:</p> + + <p><strong>$B%j%/%(%9%H(B ``<code>GET /somepath/pathinfo</code>'' + $B$,9T$J$o$l$?>l9g$N!"(B<br /> + $B%5!<%PC10L$N@_Dj(B (<code>httpd.conf</code>) $B$NFbIt(B:</strong><br /> + </p> + + <table bgcolor="#F0F0F0" cellspacing="0" cellpadding="5"> + <tr> + <td> +<pre> +<strong>$BM?$($i$l$?%k!<%k(B</strong> <strong>$BCV497k2L(B</strong> +---------------------------------------------- ---------------------------------- +^/somepath(.*) otherpath$1 $BL58z$J$N$G%5%]!<%H$7$J$$(B + +^/somepath(.*) otherpath$1 [R] $BL58z$J$N$G%5%]!<%H$7$J$$(B + +^/somepath(.*) otherpath$1 [P] $BL58z$J$N$G%5%]!<%H$7$J$$(B +---------------------------------------------- ---------------------------------- +^/somepath(.*) /otherpath$1 /otherpath/pathinfo + +^/somepath(.*) /otherpath$1 [R] $B30It%j%@%$%l%/%7%g%s7PM3$G(B + http://thishost/otherpath/pathinfo + +^/somepath(.*) /otherpath$1 [P] $BL50UL#$J$N$G%5%]!<%H$7$J$$(B +---------------------------------------------- ---------------------------------- +^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo + +^/somepath(.*) http://thishost/otherpath$1 [R] $B30It%j%@%$%l%/%7%g%s7PM3$G(B + http://thishost/otherpath/pathinfo + +^/somepath(.*) http://thishost/otherpath$1 [P] $BL50UL#$J$N$G%5%]!<%H$7$J$$(B +---------------------------------------------- ---------------------------------- +^/somepath(.*) http://otherhost/otherpath$1 $B30It%j%@%$%l%/%7%g%s7PM3$G(B + http://otherhost/otherpath/pathinfo + +^/somepath(.*) http://otherhost/otherpath$1 [R] $B30It%j%@%$%l%/%7%g%s7PM3$G(B + http://otherhost/otherpath/pathinfo + ([R] $B%U%i%0$O>iD9(B) + +^/somepath(.*) http://otherhost/otherpath$1 [P] $BFbIt%W%m%-%77PM3$G(B + http://otherhost/otherpath/pathinfo +</pre> + </td> + </tr> + </table> + + <p><strong>$B%j%/%(%9%H(B ``<code>GET /somepath/localpath/pathinfo</code>'' + $B$,9T$J$o$l$?>l9g$N!"(B<br /> + <code>/somepath</code> $B$K4X$9$k%G%#%l%/%H%jC10L$N@_Dj$NFbIt(B:<br /> + (<em>$BNc$($P(B</em>$B!"(B + <code>/physical/path/to/somepath</code> $B%G%#%l%/%H%j$K$"$C$F!"(B<br /> + <code>RewriteBase /somepath</code> $B$N5-=R$,$"$k(B + <code>.htaccess</code> $B%U%!%$%k(B):</strong><br /> + </p> + + <table bgcolor="#F0F0F0" cellspacing="0" cellpadding="5"> + <tr> + <td> +<pre> +<strong>$BM?$($i$l$?%k!<%k(B</strong> <strong>$BCV497k2L(B</strong> +---------------------------------------------- ---------------------------------- +^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo + +^localpath(.*) otherpath$1 [R] $B30It%j%@%$%l%/%7%g%s7PM3$G(B + http://thishost/somepath/otherpath/pathinfo + +^localpath(.*) otherpath$1 [P] $BL50UL#$J$N$G%5%]!<%H$7$J$$(B +---------------------------------------------- ---------------------------------- +^localpath(.*) /otherpath$1 /otherpath/pathinfo + +^localpath(.*) /otherpath$1 [R] $B30It%j%@%$%l%/%7%g%s7PM3$G(B + http://thishost/otherpath/pathinfo + +^localpath(.*) /otherpath$1 [P] $BL50UL#$J$N$G%5%]!<%H$7$J$$(B +---------------------------------------------- ---------------------------------- +^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo + +^localpath(.*) http://thishost/otherpath$1 [R] $B30It%j%@%$%l%/%7%g%s7PM3$G(B + http://thishost/otherpath/pathinfo + +^localpath(.*) http://thishost/otherpath$1 [P] $BL50UL#$J$N$G%5%]!<%H$7$J$$(B +---------------------------------------------- ---------------------------------- +^localpath(.*) http://otherhost/otherpath$1 $B30It%j%@%$%l%/%7%g%s7PM3$G(B + http://otherhost/otherpath/pathinfo + +^localpath(.*) http://otherhost/otherpath$1 [R] $B30It%j%@%$%l%/%7%g%s7PM3$G(B + http://otherhost/otherpath/pathinfo + ([R] $B%U%i%0$O>iD9(B) + +^localpath(.*) http://otherhost/otherpath$1 [P] $BFbIt%W%m%-%77PM3$G(B + http://otherhost/otherpath/pathinfo +</pre> + </td> + </tr> + </table> + + <p><strong>$BNc(B:</strong></p> + + <blockquote> + $B$3$3$G$O!"(B + <blockquote> + <code>/</code> <em>Language</em> <code>/~</code> + <em>Realname</em> <code>/.../</code> <em>File</em> + </blockquote> + + $B$H$$$&=q<0$N(B URL $B$r(B + + <blockquote> + <code>/u/</code> <em>Username</em> <code>/.../</code> + <em>File</em> <code>.</code> <em>Language</em> + </blockquote> + + $B$K=q$-49$($?$$$b$N$H$7$^$9!#(B + + <p>$BA0=R$N%^%C%W%U%!%$%k$r(B <code>/path/to/file/map.txt</code> + $B$H$$$&L>A0$GJ]B8$7$F$*$-$^$9!#$=$N8e!"(BApache $B%5!<%P@_Dj(B + $B%U%!%$%k$K0J2<$N9T$rDI2C$9$k$@$1$G$9(B:</p> + + <blockquote> +<pre> +RewriteLog /path/to/file/rewrite.log +RewriteMap real-to-user txt:/path/to/file/map.txt +RewriteRule ^/([^/]+)/~([^/]+)/(.*)$ /u/${real-to-user:$2|nobody}/$3.$1 +</pre> + </blockquote> + </blockquote> + <hr noshade="noshade" size="1" /> + + <center> + <h1><a id="Miscelleneous" + name="Miscelleneous">$B$=$NB>$N>pJs(B</a></h1> + </center> + <hr noshade="noshade" size="1" /> + + <h2><a id="EnvVar" name="EnvVar">$B4D6-JQ?t(B</a></h2> + $B$3$N%b%8%e!<%k$O!"(B<code>SCRIPT_URL</code> $B$H(B + <code>SCRIPT_URI</code> $B$H$$$&Fs$D$N(B ($BHsI8=`$N(B) CGI/SSI + $B4D6-JQ?t$r@_Dj$7$^$9!#$3$l$i$NCf$K$O8=:_$N%j%=!<%9$X$N(B<em>$BO@M}E*$J(B</em> + Web $B%S%e!<$,F~$C$F$$$^$9!#0lJ}!"I8=`$N(B CGI/SSI $BJQ?t$G$"$k(B + <code>SCRIPT_NAME</code> $B$H(B <code>SCRIPT_FILENAME</code> + $B$K$O!"(B<em>$BJ*M}E*$J(B</em>$B%7%9%F%`%S%e!<$,F~$C$F$$$^$9!#(B + + <p>$BCm0U(B: $B$3$l$i$NJQ?t$NCf$K$O!"(B<em>$B:G=i$K%j%/%(%9%H$r<u$1$?;~E@(B</em> + <em>$B$9$J$o$A(B</em>$B!"=q$-49$($,9T$o$l$k(B<em>$BA0$N(B</em> URI/URL + $B$,J];}$5$l$F$$$^$9!#(BURL $B=q$-49$(=hM}$O!"O@M}E*$J(B URL + $B$rJ*M}E*$J%Q%9L>$K=q$-49$($k$?$a$K;H$o$l$k$3$H$,B?$$$?$a!"(B + $B$3$NE@$O=EMW$G$9!#(B</p> + + <p><strong>$BNc(B:</strong></p> + + <blockquote> +<pre> +SCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html +SCRIPT_FILENAME=/u/rse/.www/index.html +SCRIPT_URL=/u/rse/ +SCRIPT_URI=http://en1.engelschall.com/u/rse/ +</pre> + </blockquote> + <hr noshade="noshade" size="1" /> + + <h2><a id="Solutions" name="Solutions">$B<BA)E*$J2r7hK!(B</a></h2> + $B$3$NJ8=q0J30$K$b!"(B<a href="../misc/rewriteguide.html">URL + Rewriting Guide</a> $B$H$$$&J8=q$,$"$j$^$9!#$3$NCf$K$O!"(BURL + $B%Y!<%9$NLdBj$K$D$$$F!"<BA)E*$J2r7hK!$,=8$a$i$l$F$$$^$9!#(B + $B$3$3$G<B:]$KLrN)$D%k!<%k%;%C%H$d(B mod_rewrite + $B$K4X$9$kDI2C>pJs$r8+$k$3$H$,$G$-$k$G$7$g$&!#(B + </blockquote> + <hr /> + + <h3 align="CENTER">Apache HTTP Server Version 1.3</h3> + <a href="./"><img src="../images/index.gif" alt="Index" /></a> + <a href="../"><img src="../images/home.gif" alt="Home" /></a> + + <!-- page indentation --> + <!--/%hypertext --> + </body> +</html> |