From f4f786080bd710064f8cba8c6f613957974800fd Mon Sep 17 00:00:00 2001 From: Henning Brauer Date: Mon, 17 Nov 2003 17:03:17 +0000 Subject: import Apache 1.3.29 and mod_ssl 2.8.16 --- usr.sbin/httpd/Announcement.de | 115 + usr.sbin/httpd/htdocs/manual/FAQ.html | 3977 ++++++++++++++++++++ .../httpd/htdocs/manual/mod/mod_rewrite.html.en | 2103 +++++++++++ .../httpd/htdocs/manual/mod/mod_rewrite.html.html | 2107 +++++++++++ .../htdocs/manual/mod/mod_rewrite.html.ja.jis | 2102 +++++++++++ 5 files changed, 10404 insertions(+) create mode 100644 usr.sbin/httpd/Announcement.de create mode 100644 usr.sbin/httpd/htdocs/manual/FAQ.html create mode 100644 usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.en create mode 100644 usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.html create mode 100644 usr.sbin/httpd/htdocs/manual/mod/mod_rewrite.html.ja.jis (limited to 'usr.sbin') diff --git a/usr.sbin/httpd/Announcement.de b/usr.sbin/httpd/Announcement.de new file mode 100644 index 00000000000..e87e17606b0 --- /dev/null +++ b/usr.sbin/httpd/Announcement.de @@ -0,0 +1,115 @@ + + Apache HTTP Server 1.3.29 freigegeben + + Wir, die Apache Software Foundation und das Apache HTTP Server Projekt, + freuen uns, die Freigabe der Version 1.3.29 des Apache HTTP Servers + ("Apache") bekannt zu geben. Diese Ankündigung führt die wesentlichen + Änderungen von 1.3.29 gegenüber 1.3.28 auf. Die Ankündigung ist auch in + englischer Sprache unter http://www.apache.org/dist/httpd/Announcement.txt + verfügbar. + + Diese Version des Apache ist vornehmlich ein Bug-Fix- und Sicherheits- + Update. Eine kurze Zusammenfassung der Bug-Fixes ist am Ende des Dokumentes + aufgeführt. Die vollständige Liste der Änderungen ist in der CHANGES- + Datei zu finden. Apache 1.3.29 behebt insbesondere 1 Sicherheitslücke. + + o CAN-2003-0542 (cve.mitre.org) + Behebung von Pufferüberläufen in mod_alias und mod_rewrite, welche + auftraten, falls reguläre Ausdrücke mit mehr als 9 speichernden + Klammernpaaren angewendet wurden. + + Wir betrachten den Apache 1.3.29 als die beste verfügbare Version des + Apache 1.3 und wir empfehlen Benutzern älterer Versionen, insbesondere + der Familien 1.1.x und 1.2.x, umgehend die Aufrüstung. Für die 1.2.x- + Familie werden keine weiteren Releases mehr erstellt. + + Apache 1.3.29 steht unter folgender Adresse zum Download bereit: + + http://httpd.apache.org/download.cgi + + Dieser Service nutzt das Mirror-Netzwerk, welches unter folgender + Adresse aufgeführt wird: + + http://www.apache.org/mirrors/ + + Eine vollständige Auflistung aller bisherigen Änderungen finden Sie in + der Datei CHANGES_1.3. + + Seit Apache 1.3.12 enthalten Binärdistributionen alle Apache-Standard- + module als Shared Objects (sofern es von der Plattform unterstützt + wird) sowie den kompletten Quelltext. Die Installation kann auf einfache + Weise mit dem beigefügten Installationsskript durchgeführt werden. + Eine vollständige Erläuterung finden Sie in den Dateien README.bindist + und INSTALL.bindist. Beachten Sie bitte, dass die Binärdistributionen + auf freiwilliger Basis angeboten werden und aktuelle Distributionen + nicht immer für spezielle Plattformen verfügbar sind. + Win32-Binärdistributionen basieren auf der Microsoft-Installer- + Technologie (.MSI). Obwohl die Entwickler diese Installationsmethode + fortlaufend stabilisieren, sollten Fragen dazu an die Newsgroup + news:comp.infosystems.www.servers.ms-windows gerichtet werden. + + Eine Übersicht der seit 1.2 eingeführten neuen Features finden Sie unter + + http://httpd.apache.org/docs/new_features_1_3.html + + Ganz allgemein bietet der Apache 1.3 wesentliche Verbesserungen gegenüber + der Version 1.2, einschliesslich besserer Performance, Zuverlässigkeit + und Unterstützung von mehr Plattformen, darunter Windows NT und 2000 (die + unter die Bezeichnung "Win32" fallen), OS2, Netware und Plattformen mit + TPF-Thread-Unterstützung. + + Apache ist der am häufigsten verwendete Webserver des bekannten + Universums. Mehr als die Hälfte aller Server im Internet laufen mit dem + Apache oder einem seiner Derivate. + + WICHTIGER HINWEIS FÜR APACHE-NUTZER: Der Apache 1.3 wurde für + Unix-Systeme entwickelt. Obwohl die Portierungen auf nicht-Unix- + Plattformen (wie zum Beispiel Win32, Netware oder OS2) von akzeptabler + Qualität sind, ist der Apache 1.3 nicht für diese Plattformen optimiert. + Sicherheits-, Stabilitäts- und Performanceprobleme zu diesen nicht-Unix- + Portierungen betreffen aufgrund der Unix-Herkunft der Software im + Allgemeinen nicht die Unix-Version. + + Der Apache 2.0 wurde durch die Einführung der Apache Portability Library + und der MPM-Module von Anfang an für mehrere Betriebssysteme konstruiert. + Nutzer von nicht-Unix-Plattformen sind dringend angehalten, aufgrund der + besseren Performance, Stabilität und Sicherheit auf den Apache 2.0 zu + wechseln. + + Wesentliche Änderungen des Apache 1.3.29 + + Sicherheitslücken + + o CAN-2003-0542 (cve.mitre.org) + Behebung von Pufferüberläufen in mod_alias und mod_rewrite, welche + auftraten, falls reguläre Ausdrücke mit mehr als 9 speichernden + Klammernpaaren angewendet wurden. + + Neue Features + + Neue Features, die sich auf bestimmte Plattformen beziehen: + + * Die ident-Funktionalität gemäß RFC1413 ist nun sowohl für + Windows- wie auch für NetWare-Plattformen verfügbar. Dies + beinhaltet auch eine alternative Thread-sichere Implementation der + Socket-Timeout-Funktionalität bei der Abfrage des identd-Daemons. + + Behobene Fehler + + Die folgenden nennenswerten Fehler wurden im Apache 1.3.28 (oder + früher) gefunden und im Apache 1.3.29 behoben: + + * Innerhalb von ap_bclose() wird nun durchweg ap_pclosesocket() für + Sockets und sp_pclosef() für Dateien aufgerufen. Ebenso wird nun + einheitlich closesocket() zum Schließen der (Dateideskriptoren von) + Sockets verwendet. Das vorherige Durcheinander von Dateideskriptoren + für Sockets und Dateien würde bei einigen Applikationen Probleme + verursachen, jetzt wo wir vorsorglich Dateideskriptoren schließen, + um Lecks zu vermeiden. PR 22805. + + * Korrektur von mod_usertrack, um keine fälschlich zutreffenden + Übereinstimmungen mit dem Namen des user-tracking-Cookies zu + erhalten. PR 16661. + + * Die Bildung von Subprozess-Zombies bei der Verwendung von CGI-Wrappern + wie suEXEC und cgiwrap wird verhindert. PR 21737. 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 @@ + + + + + + + Apache Server Frequently Asked Questions + + + + + +
+ [APACHE DOCUMENTATION] + +

Apache HTTP Server Version 1.3

+
+ + +

Apache Server Frequently Asked + Questions

+ +

The latest version of this FAQ is always available from the + main Apache web site, at <http://httpd.apache.org/docs/misc/FAQ.html>.

+ + + + + + + + + + + + + + + + +

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.

+ +

The Questions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + + + + + +
  1. + Background + +
      +
    1. What is Apache?
    2. + +
    3. How and why was Apache + created?
    4. + +
    5. Why the name "Apache"?
    6. + +
    7. OK, so how does Apache compare to + other servers?
    8. + +
    9. How thoroughly tested is + Apache?
    10. + +
    11. What are the future plans for + Apache?
    12. + +
    13. Whom do I contact for + support?
    14. + +
    15. Is there any more information on + Apache?
    16. + +
    17. Where can I get Apache?
    18. + +
    19. May I use the Apache logo on my + product or Web site?
    20. +
    +
  2. + + + + + + + + + + + + + + + + + + + +
  3. + General Technical Questions + +
      +
    1. "Why can't I ...? Why won't ... + work?" What to do in case of problems
    2. + +
    3. How compatible is Apache with + my existing NCSA 1.3 setup?
    4. + +
    5. Is Apache Year 2000 + compliant?
    6. + +
    7. How do I submit a patch to + the Apache Group?
    8. + +
    9. Why has Apache stolen my + favourite site's Internet address?
    10. + +
    11. Why am I getting spam mail from the + Apache site?
    12. + +
    13. May I include the Apache software + on a CD or other package I'm distributing?
    14. + +
    15. What's the best hardware/operating + system/... How do I get the most out of my Apache Web + server?
    16. + +
    17. What are "regular + expressions"?
    18. + +
    19. Why isn't there a binary for my + platform?
    20. +
    +
  4. + + + + + + + + + + + + + + + + + + + +
  5. + Building Apache + +
      +
    1. Why do I get an error about an + undefined reference to "__inet_ntoa" or + other __inet_* symbols?
    2. + +
    3. Why won't Apache compile with my + system's cc?
    4. + +
    5. Why do I get complaints about + redefinition of "struct iovec" when + compiling under Linux?
    6. + +
    7. I'm using gcc and I get some + compilation errors, what is wrong?
    8. + +
    9. I'm using RedHat Linux 5.0, or + some other glibc-based Linux system, and I + get errors with the crypt function when I + attempt to build Apache 1.2.
    10. +
    +
  6. + + + + + + + + + + + + + + + + + + + +
  7. + Error Log Messages and Problems Starting + Apache + +
      +
    1. Why do I get "setgid: Invalid + argument" at startup?
    2. + +
    3. Why am I getting "httpd: + could not set socket option TCP_NODELAY" in my + error log?
    4. + +
    5. Why am I getting + "connection reset by peer" in my error + log?
    6. + +
    7. The errorlog says Apache + dumped core, but where's the dump file?
    8. + +
    9. When I run it under Linux I + get "shmget: function not found", what should I + do?
    10. + +
    11. Server hangs, or fails to + start, and/or error log fills with "fcntl: + F_SETLKW: No record locks available" or similar + messages
    12. + +
    13. Why am I getting "Expected + </Directory> but saw </Directory>" + when I try to start Apache?
    14. + +
    15. I'm using RedHat Linux and I have + problems with httpd dying randomly or not restarting + properly
    16. + +
    17. I upgraded from an Apache version + earlier than 1.2.0 and suddenly I have problems with + Apache dying randomly or not restarting properly
    18. + +
    19. When I try to start Apache + from a DOS window, I get a message like "Cannot + determine host name. Use ServerName directive to set it + manually." What does this mean?
    20. + +
    21. When I try to start Apache for + Windows, I get a message like "Unable To Locate + WS2_32.DLL...". What should I do?
    22. + +
    23. Apache for Windows does + not start. Error log contains this message "[crit] + (10045) The attempted operation is not supported for the + type of object referenced: Parent: WSADuplicateSocket + failed for socket ###". What does this + mean?
    24. + +
    25. When I try to start Apache on + Windows, I get a message like "System error 1067 + has occurred. The process terminated + unexpectedly." What does this mean?
    26. + +
    27. 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 "admin: not a valid + FDN: ...." is logged.
    28. + +
    29. Why do I have weird entries in my + logs asking for default.ida and + cmd.exe?
    30. + +
    31. Why am I getting server restart + messages periodically, when I did not restart the + server?
    32. + +
    33. Why am I getting "module + module-name is not compatible with this version of + Apache" messages in my error log?
    34. + +
    +
  8. + + + + + + + + + + + + + + + + + + + +
  9. + Configuration Questions + +
      +
    1. Why can't I run more than + <n> virtual hosts?
    2. + +
    3. Can I increase + FD_SETSIZE on FreeBSD?
    4. + +
    5. Why doesn't my + ErrorDocument 401 work?
    6. + +
    7. Why does Apache send a cookie on + every response?
    8. + +
    9. Why don't my cookies work, I even + compiled in mod_cookies?
    10. + +
    11. Why do my Java app[let]s + give me plain text when I request an URL from an Apache + server?
    12. + +
    13. How do I get Apache to send a MIDI + file so the browser can play it?
    14. + +
    15. How do I add browsers and referrers + to my logs?
    16. + +
    17. Why does accessing + directories only work when I include the trailing "/" + (e.g.http://foo.domain.com/~user/) + but not when I omit it + (e.g.http://foo.domain.com/~user)?
    18. + +
    19. Why doesn't mod_info + list any directives?
    20. + +
    21. I upgraded to Apache 1.3 and now + my virtual hosts don't work!
    22. + +
    23. I'm using RedHat Linux and my + .htm files are showing up as HTML source rather than + being formatted!
    24. + +
    25. My .htaccess + files are being ignored.
    26. + +
    27. Why do I get a + "Forbidden" message whenever I try to access + a particular directory?
    28. + +
    29. Why do I get a + "Forbidden/You don't have permission to access / on + this server" message whenever I try to access my + server?
    30. + +
    31. 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?
    32. + +
    33. My site is accessible + under many different hostnames; how do I redirect clients + so that they see only a single name?
    34. + +
    35. 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?
    36. + +
    37. How do I turn automatic directory listings + on or off?
    38. + +
    39. Why do my Options directives not have + the desired effect?
    40. + +
    41. How can I change the information + that Apache returns about itself in the headers?
    42. + +
    43. Why do I see requests for other sites + appearing in my log files?
    44. + +
    +
  10. + + + + + + + + + + + + + + + + + + + +
  11. + Dynamic Content (CGI and SSI) + +
      +
    1. How do I enable CGI + execution in directories other than the + ScriptAlias?
    2. + +
    3. What does it mean + when my CGIs fail with "Premature end of script + headers"?
    4. + +
    5. Why do I keep getting + "Method Not Allowed" for form POST requests?
    6. + +
    7. How can I get my script's + output without Apache buffering it? Why doesn't my server + push work?
    8. + +
    9. Where can I find the "CGI + specification"?
    10. + +
    11. Why isn't FastCGI included with + Apache any more?
    12. + +
    13. How do I enable SSI (parsed + HTML)?
    14. + +
    15. Why don't my parsed files get + cached?
    16. + +
    17. How can I have my script + output parsed?
    18. + +
    19. SSIs don't work for + VirtualHosts and/or user home directories
    20. + +
    21. How can I use + ErrorDocument and SSI to simplify customized + error messages?
    22. + +
    23. Why is the environment + variable REMOTE_USER not set?
    24. + +
    25. How do I allow each of my user + directories to have a cgi-bin directory?
    26. +
    +
  12. + + + + + + + + + + + + + + + + + + + +
  13. + Authentication and Access Restrictions + +
      +
    1. Why isn't restricting access by + host or domain name working correctly?
    2. + +
    3. How do I set up Apache + to require a username and password to access certain + documents?
    4. + +
    5. How do I set up Apache to + allow access to certain documents only if a site is + either a local site or the user supplies a + password and username?
    6. + +
    7. Why does my + authentication give me a server error?
    8. + +
    9. Do I have to keep the + (mSQL) authentication information on the same + machine?
    10. + +
    11. Why is my mSQL authentication + terribly slow?
    12. + +
    13. Can I use my + /etc/passwd file for Web page + authentication?
    14. + +
    15. Why does Apache ask for my + password twice before serving a file?
    16. + +
    17. How can I prevent people from + "stealing" the images from my web site?
    18. + +
    +
  14. + + + + + + + + + + + + + + + + + + + +
  15. + URL Rewriting + +
      +
    1. Where can I find + mod_rewrite rulesets which already solve particular + URL-related problems?
    2. + +
    3. Where can I find any + published information about URL-manipulations and + mod_rewrite?
    4. + +
    5. Why is mod_rewrite so + difficult to learn and seems so complicated?
    6. + +
    7. What can I do if my + RewriteRules don't work as expected?
    8. + +
    9. Why don't some of my + URLs get prefixed with DocumentRoot when using + mod_rewrite?
    10. + +
    11. How can I make all my URLs + case-insensitive with mod_rewrite?
    12. + +
    13. Why are RewriteRules in + my VirtualHost parts ignored?
    14. + +
    15. How can I use + strings with whitespaces in RewriteRule's ENV + flag?
    16. +
    +
  16. + + + + + + + + + + + + + + + + + + + +
  17. + Features + +
      +
    1. Does or will Apache act as a Proxy + server?
    2. + +
    3. What are "multiviews"?
    4. + +
    5. Why can't I publish to my + Apache server using PUT on Netscape Gold and other + programs?
    6. + +
    7. Why doesn't Apache include + SSL?
    8. + +
    9. How can I attach a footer to my + documents without using SSI?
    10. + +
    11. Does Apache include a search + engine?
    12. + +
    13. How can I rotate my log + files?
    14. + +
    15. How do I keep certain + requests from appearing in my logs?
    16. + +
    17. Does Apache include any sort of + database integration?
    18. + +
    19. Can I use Active Server Pages (ASP) + with Apache?
    20. + +
    21. Does Apache come with Java + support?
    22. +
    +
  18. + + + + + + + + +
+
+ +

The Answers

+ + + + + + + + + + + + + +

A. Background

+ +
    +
  1. + What is + Apache? + +

    The Apache httpd server

    + +
      +
    • is a powerful, flexible, HTTP/1.1 compliant web + server
    • + +
    • implements the latest protocols, including HTTP/1.1 + (RFC2616)
    • + +
    • is highly configurable and extensible with + third-party modules
    • + +
    • can be customised by writing 'modules' using the + Apache module API
    • + +
    • provides full source code and comes with an + unrestrictive license
    • + +
    • runs on Windows NT/9x, Netware 5.x and above, OS/2, and most + versions of Unix, as well as several other operating + systems
    • + +
    • is actively being developed
    • + +
    • encourages user feedback through new ideas, bug + reports and patches
    • + +
    • + implements many frequently requested features, + including:
      +
      + + +
      +
      DBM databases for authentication
      + +
      allows you to easily set up password-protected + pages with enormous numbers of authorized users, + without bogging down the server.
      + +
      Customized responses to errors and problems
      + +
      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 + 500 Server Errors and perform + on-the-fly diagnostics for both users and + yourself.
      + +
      Multiple DirectoryIndex directives
      + +
      Allows you to say DirectoryIndex index.html + index.cgi, which instructs the server to + either send back index.html or run + index.cgi when a directory URL is + requested, whichever it finds in the directory.
      + +
      Unlimited flexible URL rewriting and + aliasing
      + +
      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.
      + +
      Content negotiation
      + +
      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.
      + +
      Virtual Hosts
      + +
      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.
      + +
      Configurable Reliable Piped Logs
      + +
      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.
      +
      +
    • +
    +
    +
  2. + +
  3. + How and why was Apache + created? + +

    The About + Apache 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.

    +
    +
  4. + +
  5. + Why the name + "Apache"? + +

    The name 'Apache' was chosen from respect for + the Native American Indian tribe of Apache (Indé), + well-known + for their superior skills in warfare strategy and their + inexhaustible endurance. For more information on the + Apache Nation, we suggest searching + Google, + Northernlight, or + AllTheWeb.

    + +

    Secondarily, and more popularly (though incorrectly) accepted, + it's a considered cute name which stuck. Apache is "A + PAtCHy server". It was based on + some existing code and a series of "patch files".

    + +
    +
  6. + +
  7. + OK, so how does + Apache compare to other servers? + +

    For an independent assessment, see Web + Compare.

    + +

    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.

    +
    +
  8. + +
  9. + How thoroughly tested + is Apache? + +

    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.

    +
    +
  10. + +
  11. + What are the future + plans for Apache? + +
      +
    • to continue to be an "open source" no-charge-for-use + HTTP server,
    • + +
    • to keep up with advances in HTTP protocol and web + developments in general,
    • + +
    • to collect suggestions for fixes/improvements from + its users,
    • + +
    • to respond to needs of large volume providers as well + as occasional users.
    • +
    +
    +
  12. + +
  13. + Whom do I contact + for support? + +

    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 via the bug + report page. Other questions should be directed to the + Apache HTTP + Server Users List or the + comp.infosystems.www.servers.unix + or comp.infosystems.www.servers.ms-windows + 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.

    + +

    Commercial support for Apache is, however, available + from a number of third parties.

    +
    +
  14. + +
  15. + Is there any more + information available on Apache? + +

    Indeed there is. See the main Apache web site. There + is also a regular electronic publication called Apache + Week available. Links to relevant Apache + Week articles are included below where appropriate. + There are also some Apache-specific + books available.

    +
    +
  16. + +
  17. + Where can I get + Apache? + +

    You can find out how to download the source for Apache + at the project's main + web page.

    +
    +
  18. + +
  19. + + +

    You may NOT use any original artwork from the + Apache Software Foundation, nor make or use modified + versions of such artwork, except under the following + conditions:

    + +
      +
    • You may use the 'Powered by Apache' + graphic on a Web site that is being served by the + Apache HTTP server software.
    • + +
    • You may use the aforementioned 'Powered by Apache' + graphic or the + Apache Software Foundation logo in product + description and promotional material IF and ONLY + IF 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 strictly forbidden.
    • +
    +
    +
  20. +
+ + + + + + + + + + + + + + + + + + + +

B. General Technical Questions

+ +
    +
  1. + "Why can't I ...? + Why won't ... work?" What to do in case of + problems + +

    If you are having trouble with your Apache server + software, you should take the following steps:

    + +
      +
    1. + Check the errorlog! + +

      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 + /usr/local/apache/logs/error_log, but see + the ErrorLog + directive in your config files for the location on your + server.

      +
    2. + +
    3. + Check the FAQ! + + +

      The latest version of the Apache Frequently-Asked + Questions list can always be found at the main Apache + web site.

      +
    4. + +
    5. + Check the Apache bug database + +

      Most problems that get reported to The Apache Group + are recorded in the bug database. + Please check the existing reports, + open and closed, before adding + one. If you find that your issue has already been + reported, please don't 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.

      +
    6. + +
    7. + Ask in a user support group. + +

      A lot of common problems never make it to the bug + database because there's already high Q&A traffic + about them in the Users + mailing list or comp.infosystems.www.servers.unix + and related newsgroups. These newsgroups are also + available via + Google. 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 don't see your question + already posted.

      +
    8. + +
    9. + If all else fails, report the problem in the + bug database + +

      If you've gone through those steps above that are + appropriate and have obtained no relief, then please + do let The Apache Group know about the problem + by logging + a bug report.

      + +

      If your problem involves the server crashing and + generating a core dump, please include a backtrace (if + possible). As an example,

      + +
      +
      # cd ServerRoot
      + # dbx httpd core
      + (dbx) where
      +
      + +

      (Substitute the appropriate locations for your + ServerRoot and your httpd and + core files. You may have to use + gdb instead of dbx.)

      +
    10. +
    +
    +
  2. + +
  3. + How compatible + is Apache with my existing NCSA 1.3 setup? + +

    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.

    + +

    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.

    + +

    Friendly interaction between Apache and NCSA developers + should ensure that fundamental feature enhancements stay + consistent between the two servers for the foreseeable + future.

    +
    +
  4. + +
  5. + Is Apache Year + 2000 compliant? + +

    Yes, Apache is Year 2000 compliant.

    + +

    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 + asctime() and RFC850-/RFC1036-style date + formats, too. The asctime() 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 + 20 rather than 19.

    + +

    Although Apache is Year 2000 compliant, you may still + get problems if the underlying OS has problems with dates + past year 2000 (e.g., 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 1st 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.

    + +

    Users of Apache 1.2.x should upgrade to a current + version of Apache 1.3 (see year-2000 improvements + in Apache 1.3 for details).

    + +

    The Apache HTTP Server project is an open-source + software product of the Apache Software Foundation. The + project and the Foundation cannot 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 <http://www.apache.org/info/support.cgi>.

    + +

    The Apache HTTP server software is distributed with the + following disclaimer, found in the software license:

    +
    +   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.
    + 
    +
    +
    +
  6. + +
  7. + How do I + submit a patch to the Apache Group? + +

    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 bug report + page. Improvements, modifications, and additions should + follow the instructions below.

    + +

    In general, the first course of action is to be a member + of the dev@httpd.apache.org mailing list. This + indicates to the Group that you are closely following the + latest Apache developments. Your patch file should be + generated using either 'diff -c' or + 'diff -u' against the latest CVS tree. To + submit your patch, send email to + dev@httpd.apache.org with a + Subject: line that starts with + [PATCH] 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.

    + +

    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.

    +
    +
  8. + +
  9. + Why has Apache + stolen my favourite site's Internet address? + +

    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.

    +
    +
  10. + +
  11. + Why am I getting spam + mail from the Apache site? + +

    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 previous FAQ entry for more details + on this phenomenon.

    + +

    No marketing spam originates from the Apache site. The + only mail that comes from the site goes only to addresses + that have been requested to receive the mail.

    +
    +
  12. + +
  13. + May I include the + Apache software on a CD or other package I'm + distributing? + +

    The detailed answer to this question can be found in the + Apache license, which is included in the Apache + distribution in the file LICENSE. You can also + find it on the Web at <http://www.apache.org/LICENSE.txt>.

    +
    +
  14. + +
  15. + What's the best + hardware/operating system/... How do I get the most out of + my Apache Web server? + +

    Check out Dean Gaudet's performance tuning page.

    +
    +
  16. + +
  17. + What are "regular + expressions"? + +

    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)$/.

    + +

    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 CPAN + page on regular expressions, and branching out from + there.


    +
  18. + +
  19. + Why isn't there a + binary for my platform? + +

    The developers make sure that the software builds and + works correctly on the platforms available to them; this + does not necessarily mean that your 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.

    + +

    If you don't see a kit for your platform listed in the + binary distribution area (<URL:http://httpd.apache.org/dist/httpd/binaries/>), + 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.

    + +

    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 do 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.

    +
    +
  20. +
+ + + + + + + + + + + + + + + + + + + +

C. Building Apache

+ +
    +
  1. + Why do I get an + error about an undefined reference to + "__inet_ntoa" or other __inet_* + symbols? + +

    If you have installed BIND-8 then this is + normally due to a conflict between your include files and + your libraries. BIND-8 installs its include files and + libraries /usr/local/include/ and + /usr/local/lib/, while the resolver that comes + with your system is probably installed in + /usr/include/ and /usr/lib/. If + your system uses the header files in + /usr/local/include/ before those in + /usr/include/ but you do not use the new + resolver library, then the two versions will conflict.

    + +

    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 -lbind to the + EXTRA_LDFLAGS line in your + Configuration file, then re-running + Configure, should resolve the problem. (Apache + versions 1.2.* and earlier use EXTRA_LFLAGS + instead.)

    + +

    Note:As of BIND 8.1.1, the bind + libraries and files are installed under + /usr/local/bind 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:

    + +
    +
    EXTRA_CFLAGS=-I/usr/local/bind/include
    + EXTRA_LDFLAGS=-L/usr/local/bind/lib
    + EXTRA_LIBS=-lbind
    +
    +
    +
  2. + +
  3. + Why won't Apache + compile with my system's cc? + +

    If the server won't compile on your system, it is + probably due to one of the following causes:

    + +
      +
    • The Configure script doesn't + recognize your system environment.
      + This might be either because it's completely unknown or + because the specific environment (include files, OS + version, et cetera) isn't explicitly handled. If + this happens, you may need to port the server to your OS + yourself.
    • + +
    • Your system's C compiler is + garbage.
      + 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 gcc.
    • + +
    • Your include files may be + confused.
      + 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.
    • + +
    • Your operating system or compiler may be out + of revision.
      + 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.
    • +
    + +

    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 problem + report. Be sure to include complete details, + such as the compiler & OS versions and exact error + messages.

    +
    +
  4. + +
  5. + Why do I get + complaints about redefinition of "struct + iovec" when compiling under Linux? + +

    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:

    + +
      +
    • Remove the definition of struct iovec + from your C library includes. It is located in + /usr/include/sys/uio.h. + Or,
    • + +
    • Add -DNO_WRITEV to the + EXTRA_CFLAGS line in your + Configuration and reconfigure/rebuild. This + hurts performance and should only be used as a last + resort.
    • +
    +
    +
  6. + +
  7. + I'm using gcc + and I get some compilation errors, what is + wrong? + +

    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.

    + +

    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 readv, writev, or + uio.h. This is not a bug with + Apache. You will need to re-install GCC.

    +
    +
  8. + +
  9. + I'm using + RedHat Linux 5.0, or some other glibc-based + Linux system, and I get errors with the crypt + function when I attempt to build Apache 1.2. + +

    glibc puts the crypt function + into a separate library. Edit your + src/Configuration file and set this:

    + +
    +
    EXTRA_LIBS=-lcrypt
    +
    + +

    Then re-run src/Configure and re-execute + the make.

    +
    +
  10. +
+ + + + + + + + + + + + + + + + + + + +

D. Error Log Messages and Problems Starting Apache

+ +
    +
  1. + Why do I get + "setgid: Invalid argument" at + startup? + +

    Your Group + directive (probably in conf/httpd.conf) needs + to name a group that actually exists in the + /etc/group file (or your system's equivalent). + This problem is also frequently seen when a negative number + is used in the Group directive (e.g., + "Group #-1"). Using a group name -- not + group number -- found in your system's group database + should solve this problem in all cases.

    +
    +
  2. + +
  3. + Why am I getting + "httpd: could not set socket option + TCP_NODELAY" in my error log? + +

    This message almost always indicates that the client + disconnected before Apache reached the point of calling + setsockopt() 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.

    +
    +
  4. + +
  5. + Why am I getting + "connection reset by peer" in my error + log? + +

    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.

    +
    +
  6. + +
  7. + The + errorlog says Apache dumped core, but where's the dump + file? + +

    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 setuid() 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.

    + +

    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 is a + documented way of bypassing it, it is recommended that you + bypass it only for the httpd server process if + possible.

    + +

    The canonical location for Apache's core-dump files is + the ServerRoot + directory. As of Apache version 1.3, the location can be + set via the CoreDumpDirectory + 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 started as).

    +
    +
  8. + +
  9. + When I run + it under Linux I get "shmget: function not found", what + should I do? + +

    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 + Kernel HOWTO, or the documentation provided with your + distribution, or a + Linux newsgroup/mailing list. As a last-resort + workaround, you can comment out the + #define USE_SHMGET_SCOREBOARD definition + in the LINUX section of + src/conf.h and rebuild the server (prior to + 1.3b4, simply removing + #define HAVE_SHMGET would have sufficed). + This will produce a server which is slower and less + reliable.

    +
    +
  10. + +
  11. + Server hangs, + or fails to start, and/or error log fills with + "fcntl: F_SETLKW: No record locks available" + or similar messages + +

    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.

    + +

    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 can't + be kept on an NFS-mounted filesystem.

    + +

    To cause the Web server to work around the NFS locking + limitations, include a line such as the following in your + server configuration files:

    + +
    +
    LockFile /var/run/apache-lock
    +
    + +

    The directory should not be generally writable + (e.g., don't use /var/tmp). See the + LockFile + documentation for more information.

    +
    +
  12. + +
  13. + Why am I getting + "Expected </Directory> but saw + </Directory>" when I try to start + Apache? + +

    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 problem + report #2312.

    +
    +
  14. + +
  15. + I'm using RedHat Linux + and I have problems with httpd dying randomly or not + restarting properly + +

    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.

    + +

    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.

    + +

    If you're using a custom built Apache rather than the + RedHat RPMs then you should rpm -e apache. In + particular you want the mildly broken + /etc/logrotate.d/apache script to be removed, + and you want the broken /etc/rc.d/init.d/httpd + (or httpd.init) 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.

    + +

    We can't stress enough how important it is for folks, + especially vendors to follow the stopping Apache directions + 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.

    +
    +
  16. + +
  17. + I upgraded from an + Apache version earlier than 1.2.0 and suddenly I have + problems with Apache dying randomly or not restarting + properly + +

    You should read the previous note + 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 kill -9 at times + to take out all the httpd servers. But that should not be + necessary any longer. You should follow the directions on how to stop and + restart Apache.

    + +

    As of Apache 1.3 there is a script + src/support/apachectl which, after a bit of + customization, is suitable for starting, stopping, and + restarting your server.

    +
    +
  18. + +
  19. + When I try to + start Apache from a DOS window, I get a message like + "Cannot determine host name. Use ServerName directive + to set it manually." What does this mean? + +

    It means what it says; the Apache software can't + determine the hostname of your system. Edit your + conf\httpd.conf file, look for the string + "ServerName", and make sure there's an uncommented + directive such as

    + +
    +
    ServerName localhost
    +
    + +

    or

    + +
    +
    ServerName www.foo.com
    +
    + +

    in the file. Correct it if there one there with wrong + information, or add one if you don't already have one.

    + +

    Also, make sure that your Windows system has DNS + enabled. See the TCP/IP setup component of the Networking + or Internet Options control panel.

    + +

    After verifying that DNS is enabled and that you have a + valid hostname in your ServerName directive, + try to start the server again.

    +
    +
  20. + +
  21. + When I try to start + Apache for Windows, I get a message like "Unable To + Locate WS2_32.DLL...". What should I do? + +

    Short answer: You need to install Winsock 2, available + from http://www.microsoft.com/windows95/downloads/

    + +

    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.

    +
    +
  22. + +
  23. + Apache for Windows does not + start. Error log contains this message: "[crit] + (10045) The attempted operation is not supported for the + type of object referenced: Parent: WSADuplicateSocket + failed for socket ###". What does this mean? + + +

    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.

    + +

    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 + apache.exe to the Aventail "Connect Exclusion + List".

    + +

    Apache is affected in a similar way by any + 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.

    +
    +
  24. + +
  25. + When I try to start + Apache on Windows, I get a message like "System error + 1067 has occurred. The process terminated + unexpectedly." What does this mean? + +

    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:

    +
    +    c:
    +    cd "\Program Files\Apache Group\Apache"
    +    apache
    + 
    +
    + +

    (If you don't get the prompt back, hit Control-C to + cause Apache to exit.)

    + +

    The error you see will probably be one of those + preceding this question in the FAQ.

    + +

    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.

    +
    +
  26. + +
  27. 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 "admin: not a valid + FDN: ...." is logged. + +

    + 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 /etc/httpd/suse_addmodule.conf + and /etc/httpd/suse_loadmodule.conf which are not + actually required for running your server. +


    +
  28. + +
  29. Why do I have weird entries in my + logs asking for default.ida and + cmd.exe? + +

    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 article + with more information.


    +
  30. + +
  31. Why am I getting server restart + messages periodically, when I did not restart the server? + +

    Problem: You are noticing restart messages in your error log, + periodically, when you know you did not restart the server + yourself:

    + +
    +[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
    +
    + +

    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.


    +
  32. + +
  33. Why am I getting + "module module-name is not compatible with this version + of Apache" messages in my error log? + +

    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.

    + +

    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.


    +
  34. + +
+ + + + + + + + + + + + + + + + + + + +

E. Configuration Questions

+ +
    +
  1. + Why can't I run more + than <n> virtual hosts? + +

    You are probably running into resource limitations in + your operating system. The most common limitation is the + per-process limit on file + descriptors, 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 gethostbyname()) + which needs file descriptors and doesn't complain + intelligibly when it can't get them.

    + +

    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 Listen + directive also needs a file descriptor.

    + +

    Typical values for <n> 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.

    + +

    As to what you can do about this:

    + +
      +
    1. Reduce the number of Listen + 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.
    2. + +
    3. Reduce the number of log files. You can use mod_log_config + 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 + src/support/split-logfile file.
    4. + +
    5. + Increase the number of file descriptors available to + the server (see your system's documentation on the + limit or ulimit commands). + For some systems, information on how to do this is + available in the performance + hints page. There is a specific note for FreeBSD below. + +

      For Windows 95, try modifying your + C:\CONFIG.SYS file to include a line + like

      + +
      +
      FILES=300
      +
      + +

      Remember that you'll need to reboot your Windows 95 + system in order for the new value to take effect.

      +
    6. + +
    7. "Don't do that" - try to run with fewer virtual + hosts
    8. + +
    9. Spread your operation across multiple server + processes (using Listen + for example, but see the first point) and/or ports.
    10. +
    + +

    Since this is an operating-system limitation, there's + not much else available in the way of solutions.

    + +

    As of 1.2.1 we have made attempts to work around various + limitations involving running with many descriptors. More information is + available.

    +
    +
  2. + +
  3. + Can + I increase FD_SETSIZE on FreeBSD? + + +

    On versions of FreeBSD before 3.0, the + FD_SETSIZE 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.

    + +

    If you are using a version prior to 2.2, you need to + recompile your kernel with a larger + FD_SETSIZE. This can be done by adding a line + such as:

    + +
    +
    options FD_SETSIZE nnn
    +
    + +

    to your kernel config file. Starting at version 2.2, + this is no longer necessary.

    + +

    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 + FD_SETSIZE is set to when libc is compiled. To + increase this, you have to recompile libc with a higher + FD_SETSIZE.

    + +

    In FreeBSD 3.0, the default FD_SETSIZE has + been increased to 1024 and the above limitation in the + resolver library has been removed.

    + +

    After you deal with the appropriate changes above, you + can increase the setting of FD_SETSIZE at + Apache compilation time by adding + "-DFD_SETSIZE=nnn" to the + EXTRA_CFLAGS line in your + Configuration file.

    +
    +
  4. + +
  5. + Why doesn't + my ErrorDocument 401 work? + +

    You need to use it with a URL in the form + "/foo/bar" and not one with a method and + hostname such as "http://host/foo/bar". See + the ErrorDocument + documentation for details. This was incorrectly documented + in the past.

    +
    +
  6. + +
  7. + Why does Apache + send a cookie on every response? + +

    Apache does not automatically send a cookie on + every response, unless you have re-compiled it with the mod_usertrack + module, and specifically enabled it with the CookieTracking + 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 + mod_usertrack, do not compile it into + Apache.

    +
    +
  8. + +
  9. + Why don't my + cookies work, I even compiled in + mod_cookies? + +

    Firstly, you do not need to compile in + mod_cookies in order for your scripts to work + (see the previous question for more + about mod_cookies). Apache passes on your + Set-Cookie 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.

    +
    +
  10. + +
  11. + Why do my Java app[let]s + give me plain text when I request an URL from an Apache + server? + +

    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.

    + +

    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 your + 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.

    + +

    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:

    + +
    +
    BrowserMatch Java1.0 force-response-1.0
    + BrowserMatch JDK/1.0 force-response-1.0
    +
    + +

    More information about this issue can be found in the Java + and HTTP/1.1 page at the Apache web site.

    +
    +
  12. + +
  13. + How do I get Apache to + send a MIDI file so the browser can play it? + +

    Even though the registered MIME type for MIDI files is + audio/midi, some browsers are not set up to + recognize it as such; instead, they look for + audio/x-midi. There are two things you can do + to address this:

    + +
      +
    1. Configure your browser to treat documents of type + audio/midi 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.
    2. + +
    3. + Instruct Apache to send a different + Content-type header for these files by + adding the following line to your server's + configuration files: + +
      +
      AddType audio/x-midi .mid .midi + .kar
      +
      + +

      Note that this may break browsers that do + recognize the audio/midi MIME type unless + they're prepared to also handle + audio/x-midi the same way.

      +
    4. +
    +
    +
  14. + +
  15. + How do I add browsers + and referrers to my logs? + +

    Apache provides a couple of different ways of doing + this. The recommended method is to compile the mod_log_config + module into your configuration and use the CustomLog + directive.

    + +

    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:

    + +

    + CustomLog logs/access_log "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-Agent}i\""

    + +

    This will add the values of the User-agent: + and Referer: headers, which indicate the + client and the referring page, respectively, to the end of + each line in the access log.

    + +

    You may want to check out the Apache Week + article entitled: "Gathering Visitor Information: Customizing + Your Logfiles".

    +
    +
  16. + +
  17. + Why + does accessing directories only work when I include the + trailing "/" + (e.g.http://foo.domain.com/~user/) + but not when I omit it + (e.g.http://foo.domain.com/~user)? + + +

    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.

    + +

    Add a ServerName directive + to the config file to tell it what the domain name of the + server is.

    + +

    The other thing that can occasionally cause this symptom is a + misunderstanding of the Alias directive, + resulting in an alias working with a trailing slash, and not + without one. The Alias directive is very literal, + and aliases what you tell it to. Consider the following + example:

    + +
    +        Alias /example/ /home/www/example/
    +        
    + +

    The above directive creates an alias for URLs starting with + /example/, but does not alias URLs + starting with /example. That is to say, a URL such + as http://servername.com/example/ will get the + desired content, but a URL such as + http://servername.com/example will result in a + "file not found" error.

    + +

    The following Alias, on the other hand, will + work for both cases:

    + +
    +        Alias /example /home/www/example
    +        
    + +
    +
  18. + +
  19. + Why doesn't mod_info list + any directives? + +

    The mod_info + 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 User + directive), then mod_info cannot read them in + order to list their values. An entry will be made + in the error log in this event, however.

    +
    +
  20. + +
  21. + I upgraded to + Apache 1.3 and now my virtual hosts don't + work! + +

    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 + <VirtualHost> definitions were very + complex and not well documented.

    + +

    Apache 1.3b2 introduced a new directive, NameVirtualHost, + which simplifies the rules quite a bit. However, changing + the rules like this means that your existing name-based + <VirtualHost> containers probably won't + work correctly immediately following the upgrade.

    + +

    To correct this problem, add the following line to the + beginning of your server configuration file, before + defining any virtual hosts:

    + +
    +
    NameVirtualHost n.n.n.n
    +
    + +

    Replace the "n.n.n.n" 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.

    + +

    Make sure that your name-based + <VirtualHost> blocks contain + ServerName and possibly + ServerAlias directives so Apache can be sure + to tell them apart correctly.

    + +

    Please see the Apache Virtual Host + documentation for further details about + configuration.

    +
    +
  22. + +
  23. + I'm using + RedHat Linux and my .htm files are showing up as HTML + source rather than being formatted! + +

    RedHat messed up and forgot to put a content type for + .htm files into /etc/mime.types. + Edit /etc/mime.types, find the line containing + html and add htm to it. Then + restart your httpd server:

    + +
    +
    kill -HUP `cat /var/run/httpd.pid`
    +
    + +

    Then clear your browsers' caches. (Many + browsers won't re-examine the content type after they've + reloaded a page.)

    +
    +
  24. + +
  25. + My + .htaccess files are being + ignored. + +

    This is almost always due to your AllowOverride + directive being set incorrectly for the directory in + question. If it is set to None 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 Directory + container.

    +
    +
  26. + +
  27. + Why do I get a + "Forbidden" message whenever I try to access a + particular directory? + +

    This message is generally caused because either

    + +
      +
    • The underlying file system permissions do not allow + the User/Group under which Apache is running to access + the necessary files; or
    • + +
    • The Apache configuration has some access restrictions + in place which forbid access to the files.
    • +
    + +

    You can determine which case applies to your situation + by checking the error log.

    + +

    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.

    +
    +
  28. + +
  29. + Why do I get a + "Forbidden/You don't have permission to access / on + this server" message whenever I try to access my + server? + +

    Search your conf/httpd.conf file for this + exact string: <Files ~>. If you find it, + that's your problem -- that particular <Files> + container is malformed. Delete it or replace it with + <Files ~ "^\.ht"> and restart your + server and things should work as expected.

    + +

    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.

    + +

    If you don't find this string, check out the previous question.

    +
    +
  30. + +
  31. + 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? + +

    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 application/octet-stream or + text/plain. 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 + MSDN article and a note + by Alan J. Flavell.

    + +

    The best you can do as a server administrator is to + accurately configure the mime type of your documents by editing + the mime.types file or using an AddType + 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 .txt filename + extension, but this will not work if MSIE thinks the content + looks like another file type. +


    +
  32. +
  33. + My site is accessible + under many different hostnames; how do I redirect clients + so that they see only a single name? + +

    Many sites map a variety of hostnames to the same content. + For example, www.example.com, + example.com and www.example.net 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.

    + +

    There are two techniques to implement canonical hostnames:

    + +
      +
    1. Use mod_rewrite + as described in the "Canonical Hostnames" section of the + URL Rewriting Guide.
    2. + +
    3. Use name-based + virtual hosting: + +
      +NameVirtualHost *
      +
      +<VirtualHost *>
      +  ServerName www.example.net
      +  ServerAlias example.com
      +  Redirect permanent / http://www.example.com/
      +</VirtualHost>
      +
      +<VirtualHost *>
      +  ServerName www.example.com
      +  DocumentRoot /usr/local/apache/htdocs
      +</VirtualHost> +
      +
    +
  34. + +
  35. 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? + +

    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 Port and Listen + directives in httpd.conf to use port 8000 and + then request your site using + http://yourhost.example.com:8000/. (Of course, + a very restrictive firewall may block this port as well.)

    + +
  36. + +
  37. How do I turn automatic + directory listings on or off? + +

    If a client requests a URL that designates a directory and + the directory does not contain a filename that matches the DirectoryIndex + directive, then mod_autoindex can be + configured to present a listing of the directory contents.

    + +

    To turn on automatic directory indexing, find the + Options directive that + applies to the directory and add the Indexes + keyword. For example:

    + +
    + <Directory /path/to/directory>
    +    Options +Indexes
    + </Directory> +
    + +

    To turn off automatic directory indexing, remove + the Indexes keyword from the appropriate + Options line. To turn off directory listing + for a particular subdirectory, you can use + Options -Indexes. For example:

    + +
    + <Directory /path/to/directory>
    +    Options -Indexes
    + </Directory> +
    + +
  38. + +
  39. Why do my Options + directives not have the desired effect? + +

    Directives placed in the configuration files are applied + in a very particular order, as described by How Directory, Location, and Files + sections work. In addition, each Options directive has the + effect of resetting the options to none before + adding the specified options (unless only "+" and "-" options + are used). The consequence is that Options 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 + Options directives. For example, in the following

    + +
    +<Directory /usr/local/apache/htdocs>
    +    Options Indexes
    +</Directory>
    +Options Includes ExecCGI
    +
    + +

    Includes and ExecCGI will be + off in the /usr/local/apache/htdocs + directory.

    + +

    You can usually avoid problems by either finding the + Options directive that already applies to a + specific directory and changing it, or by putting your + Options directive inside the most specific possible + <Directory> section.

    + +
  40. + + +
  41. How can I change + the information that Apache returns about itself in the + headers? + +

    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.

    + +

    For example:

    + +
    +Server: Apache/1.3.26 (Unix) mod_perl/1.26 +
    + +

    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.

    + +

    There are, however, two answers to this question: the correct answer, + and the answer that you are probably looking for.

    + +

    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 Prod will + pass the least possible amount of information:

    + +
    +Server: Apache +
    + +

    The answer you are probably looking for is how to make Apache lie + about what what it is, ie send something like:

    + +
    +Server: Bob's Happy HTTPd Server +
    + +

    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.

    + +
  42. + +
  43. Why do I see requests + for other sites appearing in my log files? + +

    A an access_log entry showing this situation could look + like this:

    + +
    63.251.56.142 - - + [25/Jul/2002:12:48:04 -0700] "GET http://www.yahoo.com/ + HTTP/1.0" 200 1456
    + +

    The question is: why did a request for + www.yahoo.com come to your server instead of + Yahoo's server? And why does the response have a status + code of 200 (success)?

    + +

    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 ProxyRequests + directive is not set on. + If you do need to run a proxy server, then you must ensure + that you secure your + server properly so that only authorized clients can use + it.

    + +

    If your server is configured properly, then the attempt to + proxy through your server will fail. If you see a status + code of 404 (file not found) in the log, then + you know that the request failed. If you see a status code + of 200 (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 + www.yahoo.com.

    + +

    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:

    + +
    +
    +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>
    +
    +...
    +
    +
    +
  44. + +
+ + + + + + + + + + + + + + + + + + + +

F. Dynamic Content (CGI and SSI)

+ +
    +
  1. + How do I enable CGI + execution in directories other than the + ScriptAlias? + +

    Apache recognizes all files in a directory named as a ScriptAlias + 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 "*.cgi" or "*.pl" or + whatever. In other words, all files in a + ScriptAlias directory are scripts, as far as Apache is + concerned.

    + +

    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 AddHandler + directive.

    + +
      +
    1. + In an appropriate section of your server configuration + files, add a line such as + +
      +
      AddHandler cgi-script .cgi
      +
      + +

      The server will then recognize that all files in + that location (and its logical descendants) that end in + ".cgi" are script files, not + documents.

      +
    2. + +
    3. Make sure that the directory location is covered by + an Options + declaration that includes the ExecCGI + option.
    4. +
    + +

    In some situations, you might not want to actually allow + all files named "*.cgi" 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 via mod_rewrite + and the following steps:

    + +
      +
    1. + Locally add to the corresponding .htaccess + file a ruleset similar to this one: + +
      +
      RewriteEngine on
      + RewriteBase /~foo/bar/
      + RewriteRule ^quux\.cgi$ - + [T=application/x-httpd-cgi]
      +
      +
    2. + +
    3. Make sure that the directory location is covered by + an Options + declaration that includes the ExecCGI and + FollowSymLinks option.
    4. +
    +
    +
  2. + +
  3. + What does it mean + when my CGIs fail with "Premature end of script + headers"? + +

    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.

    + +

    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 User and Group + 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 mod_env.

    + +

    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 print or + write statements that send your HTTP + headers:

    + +
    +
    {
    +  local ($oldbar) = $|;
    +  $cfh = select (STDOUT);
    +  $| = 1;
    +  #
    +  # print your HTTP headers here
    +  #
    +  $| = $oldbar;
    +  select ($cfh);
    + }
    +
    + +

    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 off (with $| = 0 + or the equivalent) after the statements that send the + headers, as displayed above.

    + +

    If your script isn't written in Perl, do the equivalent + thing for whatever language you are using + (e.g., for C, call fflush() after + writing the headers).

    + +

    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.

    + +

    In addition, a configuration problem in suEXEC, 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.

    +
    +
  4. + +
  5. + Why do + I keep getting "Method Not Allowed" for form POST + requests? + +

    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 CGIs outside ScriptAliased + directories for details on how to configure Apache to + treat the file in question as a CGI.

    +
    +
  6. + +
  7. + How can I + get my script's output without Apache buffering it? Why + doesn't my server push work? + +

    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 + $| 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.

    + +

    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.

    +
    +
  8. + +
  9. + Where can I find + the "CGI specification"? + +

    The Common Gateway Interface (CGI) specification can be + found at the original NCSA site < + http://hoohoo.ncsa.uiuc.edu/cgi/interface.html>. + This version hasn't been updated since 1995, and there have + been some efforts to update it.

    + +

    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 <http://web.golux.com/coar/cgi/>.

    +
    +
  10. + +
  11. + Why isn't FastCGI + included with Apache any more? + +

    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 FastCGI web site. When a + new version of Apache was released, the version of the + FastCGI module included with it would soon be out of + date.

    + +

    You can still obtain the FastCGI module for Apache from + the master FastCGI web site.

    +
    +
  12. + +
  13. + How do I + enable SSI (parsed HTML)? + +

    SSI (an acronym for Server-Side Include) directives + allow static HTML documents to be enhanced at run-time + (e.g., when delivered to a client by Apache). The + format of SSI directives is covered in the mod_include manual; + suffice it to say that Apache supports not only SSI but + xSSI (eXtended SSI) directives.

    + +

    Processing a document at run-time is called + parsing 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 next question for more information + about this.)

    + +

    To enable SSI processing, you need to

    + +
      +
    • Build your server with the mod_include + module. This is normally compiled in by default.
    • + +
    • Make sure your server configuration files have an Options + directive which permits Includes.
    • + +
    • + 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 AddHandler + directive: + +
      +
      AddHandler server-parsed .shtml
      +
      + +

      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.

      +
    • +
    + +

    For additional information, see the Apache + Week article on Using Server Side Includes.

    +
    +
  14. + +
  15. + Why don't my + parsed files get cached? + +

    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 Content-Length or + Last-Modified headers. Caches commonly work by + comparing the Last-Modified 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.

    + +

    You can work around this in some cases by causing an + Expires header to be generated. (See the mod_expires documentation for + more details.) Another possibility is to use the XBitHack Full mechanism, which + tells Apache to send (under certain circumstances detailed + in the XBitHack directive description) a + Last-Modified 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.

    +
    +
  16. + +
  17. + How can I + have my script output parsed? + +

    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.

    + +

    This is a feature The Apache Group hopes to add in the + next major release after 1.3.

    +
    +
  18. + +
  19. + SSIs don't + work for VirtualHosts and/or user home + directories. + +

    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.

    +
    +
  20. + +
  21. + How can I + use ErrorDocument and SSI to simplify + customized error messages? + +

    Have a look at this + document. It shows in example form how you can a + combination of XSSI and negotiation to tailor a set of + ErrorDocuments to your personal taste, and + returning different internationalized error responses based + on the client's native language.

    +
    +
  22. + +
  23. + Why + is the environment variable REMOTE_USER not + set? + +

    This variable is set and thus available in SSI or CGI + scripts if and only if the requested + document was protected by access authentication. For an + explanation on how to implement these restrictions, see Apache + Week's articles on Using + User Authentication or DBM + User Authentication.

    + +

    Hint: When using a CGI script to receive the data of a + HTML FORM notice that protecting the document + containing the FORM is not sufficient to + provide REMOTE_USER 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).

    +
    +
  24. + +
  25. + How do I allow + each of my user directories to have a cgi-bin + directory? + +

    Remember that CGI execution does not need to be + restricted only to cgi-bin directories. You can allow CGI script execution in + arbitrary parts of your filesystem.

    + +

    There are many ways to give each user directory a + cgi-bin directory such that anything requested as + http://example.com/~user/cgi-bin/program will + be executed as a CGI script. Two alternatives are:

    + +
      +
    1. + Place the cgi-bin directory next to the public_html + directory: + +
      +
      ScriptAliasMatch ^/~([^/]*)/cgi-bin/(.*) + /home/$1/cgi-bin/$2
      +
      +
    2. + +
    3. + Place the cgi-bin directory underneath the public_html + directory: + +
      +
      <Directory + /home/*/public_html/cgi-bin>
      +     Options ExecCGI
      +     SetHandler cgi-script
      + </Directory>
      +
      +
    4. +
    +

    If you are using suexec, the first technique will not work + because CGI scripts must be stored under the public_html + directory.

    + +
    +
  26. +
+ + + + + + + + + + + + + + + + + + + +

G. Authentication and Access Restrictions

+ +
    +
  1. + Why isn't + restricting access by host or domain name working + correctly? + +

    Two of the most common causes of this are:

    + +
      +
    1. An error, inconsistency, or unexpected + mapping in the DNS registration
      + This happens frequently: your configuration restricts + access to Host.FooBar.Com, but you can't get + in from that host. The usual reason for this is that + Host.FooBar.Com is actually an alias for + another name, and when Apache performs the + address-to-name lookup it's getting the real + name, not Host.FooBar.Com. 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.
    2. + +
    3. + Inadequate checking and verification in your + configuration of Apache
      + 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 -DMAXIMUM_DNS clause + to the EXTRA_CFLAGS definition in your + Configuration file. For example: + +
      +
      EXTRA_CFLAGS=-DMAXIMUM_DNS
      +
      + +

      This will cause Apache to be very paranoid about + making sure a particular host address is + really assigned to the name it claims to be. + Note that this can incur a significant + performance penalty, however, because of all the name + resolution requests being sent to a nameserver.

      +
    4. +
    +
    +
  2. + +
  3. + How do I set up Apache + to require a username and password to access certain + documents? + +

    There are several ways to do this; some of the more + popular ones are to use the mod_auth, mod_auth_db, or mod_auth_dbm + modules.

    + +

    For an explanation on how to implement these + restrictions, see Apache + Week's articles on Using + User Authentication or DBM + User Authentication, or see the authentication tutorial in the + Apache documentation.

    +
    +
  4. + +
  5. + How do I set up Apache to + allow access to certain documents only if a site is either + a local site or the user supplies a password and + username? + +

    Use the Satisfy + directive, in particular the Satisfy Any + directive, to require that only one of the access + restrictions be met. For example, adding the following + configuration to a .htaccess 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:

    + +
    +
    Deny from all
    + Allow from .domain.com
    + AuthType Basic
    + AuthUserFile /usr/local/apache/conf/htpasswd.users
    + AuthName "special directory"
    + Require valid-user
    + Satisfy any
    +
    + +

    See the user + authentication question and the mod_access module for + details on how the above directives work.

    +
    +
  6. + +
  7. + Why does my authentication + give me a server error? + +

    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.

    + +

    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 + http_request handler will give one of the + following, confusing, errors:

    + +
      +
    • check access
    • + +
    • check user. No user file?
    • + +
    • check access. No groups file?
    • +
    + +

    This does not mean that you have to add an + 'AuthUserFile /dev/null' line as some + magazines suggest!

    + +

    The solution is to ensure that at least the last module + is authoritative and CONFIGURED. By + default, mod_auth is authoritative and will + give an OK/Denied, but only if it is configured with the + proper AuthUserFile. 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 Configuration file.)

    + +

    A typical situation for this error is when you are using + the mod_auth_dbm, mod_auth_msql, + mod_auth_mysql, mod_auth_anon or + mod_auth_cookie modules on their own. These + are by default not 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 + 'XXXAuthoritative yes' line to the + configuration.

    + +

    In general it is a good idea (though not terribly + efficient) to have the file-based mod_auth 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.

    +
    +
  8. + +
  9. + Do I have to keep the + (mSQL) authentication information on the same + machine? + +

    Some organizations feel very strongly about keeping the + authentication information on a different machine than the + webserver. With the mod_auth_msql, + mod_auth_mysql, and other SQL modules + connecting to (R)DBMses this is quite possible. Just + configure an explicit host to contact.

    + +

    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 + auth_* modules and play with the compile time + flags to alleviate this somewhat, if your RDBMS licences + allow for it.

    +
    +
  10. + +
  11. + Why is my mSQL + authentication terribly slow? + +

    You have probably configured the Host by specifying a + FQHN, and thus the libmsql will use a full + blown TCP/IP socket to talk to the database, rather than a + fast internal device. The libmsql, the mSQL + FAQ, and the mod_auth_msql documentation warn + you about this. If you have to use different hosts, check + out the mod_auth_msql code for some compile + time flags which might - or might not - suit you.

    +
    +
  12. + +
  13. + Can I use my + /etc/passwd file for Web page + authentication? + +

    Yes, you can - but it's a very bad + idea. Here are some of the reasons:

    + +
      +
    • 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 root 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 n failed passwords for the same account + within m seconds) and evasion (breaking the + connection, disabling the account under attack, disabling + all logins from that source, et + cetera), but the Web does not.
    • + +
    • 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.
    • + +
    • 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 - + if you look at the logs.
    • + +
    • 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!"
    • + +
    • Since HTTP is stateless, information about the + authentication is transmitted each and every + time 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.
    • + +
    • 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"?
    • +
    + +

    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.

    +
    +
  14. + +
  15. + Why + does Apache ask for my password twice before serving a + file? + +

    If the hostname under which you are accessing the server + is different than the hostname specified in the ServerName + directive, then depending on the setting of the UseCanonicalName + 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.

    + +

    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.

    + +

    To eliminate this problem you should

    + +
      +
    1. Always use the trailing slash when requesting + directories;
    2. + +
    3. Change the ServerName to match the name + you are using in the URL; and/or
    4. + +
    5. Set UseCanonicalName off.
    6. +
    +
    +
  16. + +
  17. + How can I prevent + people from "stealing" the images from my web site? + +

    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.

    + +

    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).

    + +

    The following configuration will produce the desired effect + if the browser passes correct REFERER headers.

    + +
    +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>
    +
    + +

    Further examples can be found in the Environment Variables documentation.

    + +
    +
  18. + + +
+ + + + + + + + + + + + + + + + + + + +

H. URL Rewriting

+ +
    +
  1. + Where can I find + mod_rewrite rulesets which already solve particular + URL-related problems? + +

    There is a collection of Practical + Solutions for URL-Manipulation where you can find all + typical solutions the author of mod_rewrite + currently knows of. If you have more interesting rulesets + which solve particular problems not currently covered in + this document, send it to Ralf S. Engelschall for + inclusion. The other webmasters will thank you for avoiding + the reinvention of the wheel.

    +
    +
  2. + +
  3. + Where can I find any + published information about URL-manipulations and + mod_rewrite? + +

    There is an article from Ralf S. Engelschall about + URL-manipulations based on mod_rewrite + in the "iX Multiuser Multitasking Magazin" issue #12/96. + The german (original) version can be read online at <http://www.heise.de/ix/artikel/9612149/>, + the English (translated) version can be found at <http://www.heise.de/ix/artikel/E/9612149/>.

    +
    +
  4. + +
  5. + Why is mod_rewrite so + difficult to learn and seems so complicated? + +

    Hmmm... there are a lot of reasons. First, mod_rewrite + itself is a powerful module which can help you in really + all 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.

    + +

    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 .htaccess 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.

    +
    +
  6. + +
  7. + What can I do if my + RewriteRules don't work as expected? + +

    Use "RewriteLog somefile" and + "RewriteLogLevel 9" 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.

    +
    +
  8. + +
  9. + Why don't some of my + URLs get prefixed with DocumentRoot when using + mod_rewrite? + +

    If the rule starts with /somedir/... make + sure that really no /somedir exists on the + filesystem if you don't want to lead the URL to match this + directory, i.e., there must be no root directory + named somedir 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.

    +
    +
  10. + +
  11. + How + can I make all my URLs case-insensitive with + mod_rewrite? + +

    You can't! The reasons are: first, that, case + translations for arbitrary length URLs cannot be done + via regex patterns and corresponding + substitutions. One needs a per-character pattern like the + sed/Perl tr|..|..| 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.

    + +

    But there is a module named mod_speling.c in + the Apache distribution. Try this module to help correct + people who use mis-cased URLs.

    +
    +
  12. + +
  13. + Why are RewriteRules in my + VirtualHost parts ignored? + +

    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.

    +
    +
  14. + +
  15. + How can I use strings + with whitespaces in RewriteRule's ENV flag? + +

    There is only one ugly solution: You have to surround + the complete flag argument by quotation marks + ("[E=...]"). Notice: The argument to quote + here is not the argument to the E-flag, it is the argument + of the Apache config file parser, i.e., the third + argument of the RewriteRule here. So you have to write + "[E=any text with whitespaces]".

    +
    +
  16. +
+ + + + + + + + + + + + + + + + + + + +

I. Features

+ +
    +
  1. + Does or will Apache act + as a Proxy server? + +

    Apache version 1.1 and above comes with a proxy module. If compiled + in, this will make Apache act as a caching-proxy + server.

    +
    +
  2. + +
  3. + What are + "multiviews"? + +

    "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 content negotiation description page. In + addition, Apache Week carried an article on + this subject entitled "Content Negotiation + Explained".

    +
    +
  4. + +
  5. + Why can't I + publish to my Apache server using PUT on Netscape Gold and + other programs? + +

    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 Apache Week article Publishing + Pages with PUT.

    +
    +
  6. + +
  7. + Why doesn't Apache + include SSL? + +

    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 RSA Data + Security, who restricts its use without a license.

    + +

    Some SSL implementations of Apache are available, + however; see the "related + projects" page at the main Apache web site.

    + +

    You can find out more about this topic in the + Apache Week article about Apache and Secure + Transactions.

    +
    +
  8. + +
  9. + How can I attach a + footer to my documents without using SSI? + +

    You can make arbitrary changes to static documents by + configuring an Action 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 + PATH_TRANSLATED environment variable), along + with whatever footer is needed.

    + +

    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 Apache + Module Registry which will add footers to documents. + These include mod_trailer, PHP + (php3_auto_append_file), mod_layout, and + mod_perl (Apache::Sandwich).

    +
    +
  10. + +
  11. + Does Apache include a + search engine? + +

    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 Web Site + Search Tools page. Open source search engines that are + often used with Apache include ht://Dig and SWISH-E.

    +
    +
  12. + +
  13. + How can I rotate my + log files? + +

    The simple answer: by piping the transfer log into an + appropriate log file rotation utility.

    + +

    The longer answer: In the src/support/ directory, you + will find a utility called rotatelogs which can + be used like this:

    +
    +   TransferLog "|/path/to/rotatelogs /path/to/logs/access_log 86400"
    +
    + +

    to enable daily rotation of the log files.
    + A more sophisticated solution of a logfile rotation + utility is available under the name cronolog + from Andrew Ford's site at http://www.cronolog.org/. + 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 Apache + License). Use it like this:

    +
    +   CustomLog "|/path/to/cronolog --symlink=/usr/local/apache/logs/access_log /usr/local/apache/logs/%Y/%m/access_log" combined
    +
    +
    +
  14. + +
  15. + How do I keep certain + requests from appearing in my logs? + +

    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 SetEnvIf + directive to set an environment variable for certain + requests and then using the conditional + CustomLog syntax to prevent logging when the + environment variable is set.

    +
    +
  16. + +
  17. + Does Apache support any + sort of database integration? + +

    No. Apache is a Web (HTTP) server, not an application + server. The base package does not include any such + functionality. See the PHP + project and the mod_perl project for + examples of modules that allow you to work with databases + from within the Apache environment.

    +
    +
  18. + +
  19. + Can I use Active Server Pages + (ASP) with Apache? + +

    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 related + projects page to find out more.

    +
    +
  20. + +
  21. + Does Apache come with Java + support? + +

    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:http://jakarta.apache.org/>.

    +
    +
  22. +
+ + + + + + +
+ +

Apache HTTP Server Version 1.3

+ Index + Home + + + + 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 @@ + + + + + + + + + + Apache module mod_rewrite + + + + +
+ +
+ [APACHE DOCUMENTATION] + +

Apache HTTP Server Version 1.3

+
+ +
+ + +

Module mod_rewrite
+ URL Rewriting Engine

+ +

This module provides a rule-based rewriting engine to + rewrite requested URLs on the fly.

+ +

Status: Extension
+ Source File: + mod_rewrite.c
+ Module Identifier: + rewrite_module
+ Compatibility: Available in + Apache 1.2 and later.

+
+
+ + +

Summary

+ +
+
+
+ ``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.'' + + +
+ -- Brian Behlendorf
+ Apache Group +
+
+
+
+ +
+
+
+ `` Despite the tons of examples and docs, + mod_rewrite is voodoo. Damned cool voodoo, but still + voodoo. '' + +
+ -- Brian Moore
+ bem@news.cmc.net +
+
+
+
+ Welcome to mod_rewrite, the Swiss Army Knife of URL + manipulation! + +

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.

+ +

This module operates on the full URLs (including the + path-info part) both in per-server context + (httpd.conf) and per-directory context + (.htaccess) 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.

+ +

But all this functionality and flexibility has its + drawback: complexity. So don't expect to understand this + entire module in just one day.

+ +

This module was invented and originally written in April + 1996
+ and gifted exclusively to the The Apache Group in July 1997 + by

+ +
+ Ralf S. + Engelschall
+ rse@engelschall.com
+ www.engelschall.com +
+
+ +

Table Of Contents

+ +

Internal Processing

+ + + +

Configuration Directives

+ + + Miscellaneous + + +
+ +
+

Internal + Processing

+
+
+ +

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.

+ +

API + Phases

+ +

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 (.htaccess) have been read, but + before the content handler is activated.

+ +

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:

+ +
    +
  1. 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.
  2. + +
  3. + Unbelievably mod_rewrite provides URL manipulations in + per-directory context, i.e., within + .htaccess files, although these are reached + a very long time after the URLs have been translated to + filenames. It has to be this way because + .htaccess 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 RewriteBase 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. + +

    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.

    +
  4. +
+ +

Don't forget these two points!

+ +

Ruleset + Processing

+ 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. + +

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 (RewriteRule + directives) and when a particular rule matches it optionally + loops through existing corresponding conditions + (RewriteCond 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.

+ +
+ + + + + + + + +
[Needs graphics capability to display]
Figure 1: The + control flow through the rewriting ruleset
+
+ +

As you can see, first the URL is matched against the + Pattern of each rule. When it fails mod_rewrite + immediately stops processing this rule and continues with the + next rule. If the Pattern 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 Substitution 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 TestString by expanding variables, + back-references, map lookups, etc. and then we try + to match CondPattern 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 + Substitution.

+ +

Quoting Special + Characters

+ +

As of Apache 1.3.20, special characters in + TestString and Substitution 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 Substitution string by + using '\$'; this keeps mod_rewrite from trying + to treat it as a backreference.

+ +

Regex + Back-Reference Availability

+ One important thing here has to be remembered: Whenever you + use parentheses in Pattern or in one of the + CondPattern, back-references are internally created + which can be used with the strings $N and + %N (see below). These are available for creating + the strings Substitution and TestString. + Figure 2 shows to which locations the back-references are + transfered for expansion. + +
+ + + + + + + + +
[Needs graphics capability to display]
Figure 2: The + back-reference flow through a rule
+
+ +

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.

+
+ +
+

Configuration Directives

+
+
+ +

RewriteEngine

+ Syntax: RewriteEngine + on|off
+ Default: RewriteEngine + off
+ Context: server config, + virtual host, directory, .htaccess
+ Override: FileInfo
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache + 1.2
+ + +

The RewriteEngine directive enables or + disables the runtime rewriting engine. If it is set to + off this module does no runtime processing at + all. It does not even update the SCRIPT_URx + environment variables.

+ +

Use this directive to disable the module instead of + commenting out all the RewriteRule + directives!

+ +

Note that, by default, rewrite configurations are not + inherited. This means that you need to have a + RewriteEngine on directive for each virtual host + in which you wish to use it.

+
+ +

RewriteOptions

+ Syntax: RewriteOptions + Option
+ Default: RewriteOptions + MaxRedirects=10
+ Context: server config, + virtual host, directory, .htaccess
+ Override: FileInfo
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache + 1.2; MaxRedirects is available in Apache 1.3.28 and + later
+ + +

The RewriteOptions directive sets some + special options for the current per-server or per-directory + configuration. The Option strings can be one of the + following:

+ +
+
inherit
+
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 + .htaccess configuration are inherited.
+ +
MaxRedirects=number
+
In order to prevent endless loops of internal redirects + issued by per-directory RewriteRules, + mod_rewrite 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.
+
+
+ +

RewriteLog

+ Syntax: RewriteLog + file-path
+ Default: None
+ Context: server config, + virtual host
+ Override: Not + applicable
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache + 1.2
+ + +

The RewriteLog 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 + ('/') then it is assumed to be relative to the + Server Root. The directive should occur only once + per server config.

+ + + + + +
Note: To disable the logging of + rewriting actions it is not recommended to set + file-path to /dev/null, because + although the rewriting engine does not then output to a + logfile it still creates the logfile output internally. + This will slow down the server with no advantage + to the administrator! To disable logging either + remove or comment out the RewriteLog + directive or use RewriteLogLevel 0!
+ + + + + +
Security: See the Apache Security + Tips 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.
+ +

Example:

+ +
+
+RewriteLog "/usr/local/var/apache/logs/rewrite.log"
+
+
+
+ +

RewriteLogLevel

+ Syntax: RewriteLogLevel + Level
+ Default: + RewriteLogLevel 0
+ Context: server config, + virtual host
+ Override: Not + applicable
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache + 1.2
+ + +

The RewriteLogLevel 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.

+ +

To disable the logging of rewriting actions simply set + Level to 0. This disables all rewrite action + logs.

+ + + + + +
Notice: Using a high value for + Level will slow down your Apache server + dramatically! Use the rewriting logfile at a + Level greater than 2 only for debugging!
+ +

Example:

+ +
+
+RewriteLogLevel 3
+
+
+
+ +

RewriteLock

+ Syntax: RewriteLock + file-path
+ Default: None
+ Context: server config
+ Override: Not + applicable
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache + 1.3
+ + +

This directive sets the filename for a synchronization + lockfile which mod_rewrite needs to communicate with + RewriteMap programs. 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.

+
+ +

RewriteMap

+ Syntax: RewriteMap + MapName MapType:MapSource
+ Default: not used per + default
+ Context: server config, + virtual host
+ Override: Not + applicable
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache 1.2 + (partially), Apache 1.3
+ + +

The RewriteMap directive defines a + Rewriting Map 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.

+ +

The MapName 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:

+ +
+ ${ MapName : + LookupKey }
+ ${ MapName : + LookupKey | DefaultValue + }
+
+ When such a construct occurs the map MapName is + consulted and the key LookupKey is looked-up. If the + key is found, the map-function construct is substituted by + SubstValue. If the key is not found then it is + substituted by DefaultValue or by the empty string + if no DefaultValue was specified. + +

The following combinations for MapType and + MapSource can be used:

+ + + The RewriteMap directive can occur more than + once. For each mapping-function use one + RewriteMap directive to declare its rewriting + mapfile. While you cannot declare a map in + per-directory context it is of course possible to + use this map in per-directory context. + + + + + +
Note: For plain text and DBM format + files the looked-up keys are cached in-core until the + mtime of the mapfile changes or the server + does a restart. This way you can have map-functions in + rules which are used for every request. + This is no problem, because the external lookup only + happens once!
+
+ +

RewriteBase

+ Syntax: RewriteBase + URL-path
+ Default: default is the + physical directory path
+ Context: directory, + .htaccess
+ Override: + FileInfo
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache + 1.2
+ + +

The RewriteBase directive explicitly sets the + base URL for per-directory rewrites. As you will see below, + RewriteRule can be used in per-directory config + files (.htaccess). There it will act locally, + i.e., 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.

+ +

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. But at most websites URLs are NOT + directly related to physical filename paths, so this + assumption will usually be wrong! There you have to + use the RewriteBase directive to specify the + correct URL-prefix.

+ + + + + +
Notice: If your webserver's URLs are + not directly related to physical file + paths, you have to use RewriteBase in every + .htaccess files where you want to use + RewriteRule directives.
+ +

Example:

+ +
+ Assume the following per-directory config file: + + + + + +
+
+#
+#  /abc/def/.htaccess -- per-dir config file for directory /abc/def
+#  Remember: /abc/def is the physical path of /xyz, i.e., the server
+#            has a 'Alias /xyz /abc/def' directive e.g.
+#
+
+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
+
+
+ +

In the above example, a request to + /xyz/oldstuff.html gets correctly rewritten to + the physical file /abc/def/newstuff.html.

+ + + + + +
+ Note - For Apache + hackers:
+ The following list gives detailed information about + the internal processing steps:
+
+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
+
+
+ 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. +
+
+
+ +

RewriteCond

+ Syntax: RewriteCond + TestString CondPattern
+ Default: None
+ Context: server config, + virtual host, directory, .htaccess
+ Override: + FileInfo
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache 1.2 + (partially), Apache 1.3
+ + +

The RewriteCond directive defines a rule + condition. Precede a RewriteRule directive with + one or more RewriteCond directives. The + following rewriting rule is only used if its pattern matches + the current state of the URI and if these + additional conditions apply too.

+ +

TestString is a string which can contains the + following expanded constructs in addition to plain text:

+ + + +

Special Notes:

+ +
    +
  1. The variables SCRIPT_FILENAME and REQUEST_FILENAME + contain the same value, i.e., the value of the + filename field of the internal + request_rec 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 + uri field of request_rec).
  2. + +
  3. There is the special format: + %{ENV:variable} where variable can be + any environment variable. This is looked-up via internal + Apache structures and (if not found there) via + getenv() from the Apache server process.
  4. + +
  5. There is the special format: + %{HTTP:header} where header can be + any HTTP MIME-header name. This is looked-up from the HTTP + request. Example: %{HTTP:Proxy-Connection} is + the value of the HTTP header + ``Proxy-Connection:''.
  6. + +
  7. There is the special format + %{LA-U:variable} for look-aheads which perform + an internal (URL-based) sub-request to determine the final + value of variable. 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 + REMOTE_USER variable from within the + per-server context (httpd.conf file) you have + to use %{LA-U:REMOTE_USER} because this + variable is set by the authorization phases which come + after the URL translation phase where mod_rewrite + operates. On the other hand, because mod_rewrite implements + its per-directory context (.htaccess file) via + the Fixup phase of the API and because the authorization + phases come before this phase, you just can use + %{REMOTE_USER} there.
  8. + +
  9. There is the special format: + %{LA-F:variable} which performs an internal + (filename-based) sub-request to determine the final value + of variable. Most of the time this is the same as + LA-U above.
  10. +
+ +

CondPattern is the condition pattern, + i.e., a regular expression which is applied to the + current instance of the TestString, i.e., + TestString is evaluated and then matched against + CondPattern.

+ +

Remember: CondPattern is a + standard Extended Regular Expression with some + additions:

+ +
    +
  1. You can prefix the pattern string with a + '!' character (exclamation mark) to specify a + non-matching pattern.
  2. + +
  3. + There are some special variants of CondPatterns. + Instead of real regular expression strings you can also + use one of the following: + +
      +
    • '<CondPattern' (is lexically + lower)
      + Treats the CondPattern as a plain string and + compares it lexically to TestString. True if + TestString is lexically lower than + CondPattern.
    • + +
    • '>CondPattern' (is lexically + greater)
      + Treats the CondPattern as a plain string and + compares it lexically to TestString. True if + TestString is lexically greater than + CondPattern.
    • + +
    • '=CondPattern' (is lexically + equal)
      + Treats the CondPattern as a plain string and + compares it lexically to TestString. True if + TestString is lexically equal to + CondPattern, i.e the two strings are exactly + equal (character by character). If CondPattern + is just "" (two quotation marks) this + compares TestString to the empty string.
    • + +
    • '-d' (is + directory)
      + Treats the TestString as a pathname and tests + if it exists and is a directory.
    • + +
    • '-f' (is regular + file)
      + Treats the TestString as a pathname and tests + if it exists and is a regular file.
    • + +
    • '-s' (is regular file with + size)
      + Treats the TestString as a pathname and tests + if it exists and is a regular file with size greater + than zero.
    • + +
    • '-l' (is symbolic + link)
      + Treats the TestString as a pathname and tests + if it exists and is a symbolic link.
    • + +
    • '-F' (is existing file via + subrequest)
      + Checks if TestString 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!
    • + +
    • '-U' (is existing URL via + subrequest)
      + Checks if TestString 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!
    • +
    + + + + + +
    Notice: All of these tests can + also be prefixed by an exclamation mark ('!') to + negate their meaning.
    +
  4. +
+ +

Additionally you can set special flags for + CondPattern by appending

+ +
+ [flags] +
+ as the third argument to the RewriteCond + directive. Flags is a comma-separated list of the + following flags: + + + +

Example:

+ +
+ To rewrite the Homepage of a site according to the + ``User-Agent:'' header of the request, you can + use the following: + +
+
+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]
+
+
+ Interpretation: If you use Netscape Navigator as your + browser (which identifies itself as 'Mozilla'), then you + get the max homepage, which includes Frames, etc. + If you use the Lynx browser (which is Terminal-based), then + you get the min homepage, which contains no images, no + tables, etc. If you use any other browser you get + the standard homepage. +
+
+ +

RewriteRule

+ Syntax: RewriteRule + Pattern Substitution
+ Default: None
+ Context: server config, + virtual host, directory, .htaccess
+ Override: + FileInfo
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache 1.2 + (partially), Apache 1.3
+ + +

The RewriteRule directive is the real + rewriting workhorse. The directive can occur more than once. + Each directive then defines one single rewriting rule. The + definition order of these rules is + important, because this order is used when + applying the rules at run-time.

+ +

Pattern can + be (for Apache 1.1.x a System V8 and for Apache 1.2.x and + later a POSIX) regular + expression 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.

+ +

Some hints about the syntax of regular expressions:

+ + + + + +
+
+Text:
+  .           Any single character
+  [chars]     Character class: One  of chars
+  [^chars]    Character class: None of chars
+  text1|text2 Alternative: text1 or text2
+
+Quantifiers:
+  ?           0 or 1 of the preceding text
+  *           0 or N of the preceding text (N > 0)
+  +           1 or N of the preceding text (N > 1)
+
+Grouping:
+  (text)      Grouping of text
+              (either to set the borders of an alternative or
+              for making backreferences where the Nth group can 
+              be used on the RHS of a RewriteRule with $N)
+
+Anchors:
+  ^           Start of line anchor
+  $           End   of line anchor
+
+Escaping:
+  \char       escape that particular char
+              (for instance to specify the chars ".[]()" etc.)
+
+
+ +

For more information about regular expressions either have + a look at your local regex(3) manpage or its + src/regex/regex.3 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, etc.) have a look at the + following dedicated book on this topic:

+ +
+ Mastering Regular Expressions
+ Jeffrey E.F. Friedl
+ Nutshell Handbook Series
+ O'Reilly & Associates, Inc. 1997
+ ISBN 1-56592-257-3
+
+ +

Additionally in mod_rewrite the NOT character + ('!') is a possible pattern prefix. This gives + you the ability to negate a pattern; to say, for instance: + ``if the current URL does NOT match this + pattern''. This can be used for exceptional cases, where + it is easier to match the negative pattern, or as a last + default rule.

+ + + + + +
Notice: 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 $N in the substitution + string!
+ +

Substitution of a + rewriting rule is the string which is substituted for (or + replaces) the original URL for which Pattern + matched. Beside plain text you can use

+ +
    +
  1. back-references $N to the RewriteRule + pattern
  2. + +
  3. back-references %N to the last matched + RewriteCond pattern
  4. + +
  5. server-variables as in rule condition test-strings + (%{VARNAME})
  6. + +
  7. mapping-function calls + (${mapname:key|default})
  8. +
+ Back-references are $N + (N=0..9) identifiers which will be replaced + by the contents of the Nth group of the + matched Pattern. The server-variables are the same + as for the TestString of a RewriteCond + directive. The mapping-functions come from the + RewriteMap directive and are explained there. + These three types of variables are expanded in the order of + the above list. + +

As already mentioned above, all the rewriting rules are + applied to the Substitution (in the order of + definition in the config file). The URL is completely + replaced by the Substitution and the + rewriting process goes on until there are no more rules + unless explicitly terminated by a + L flag - see below.

+ +

There is a special substitution string named + '-' which means: NO + substitution! Sounds silly? No, it is useful to + provide rewriting rules which only match + some URLs but do no substitution, e.g., in + conjunction with the C (chain) flag to be + able to have more than one pattern to be applied before a + substitution occurs.

+ +

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.

+ + + + + +
Note: There is a special feature: + When you prefix a substitution field with + http://thishost[:thisport] + then mod_rewrite 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.
+ + + + + +
Remember: An unconditional external + redirect to your own server will not work with the prefix + http://thishost because of this feature. To + achieve such a self-redirect, you have to use the + R-flag (see below).
+ +

Additionally you can set special flags for + Substitution by appending

+ +
+ [flags] +
+ as the third argument to the RewriteRule + directive. Flags is a comma-separated list of the + following flags: + + + + + + + +
+ Note: Never forget that + Pattern is applied to a complete URL in + per-server configuration files. But in + per-directory configuration files, the per-directory + prefix (which always is the same for a specific + directory!) is automatically removed for the + pattern matching and automatically added after + the substitution has been done. 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. + +

There is one exception: If a substitution string + starts with ``http://'' then the directory + prefix will not be added and an + external redirect or proxy throughput (if flag + P is used!) is forced!

+
+ + + + + +
Note: To enable the rewriting engine + for per-directory configuration files you need to set + ``RewriteEngine On'' in these files + and ``Options + FollowSymLinks'' must be enabled. If your + administrator has disabled override of + FollowSymLinks for a user's directory, then + you cannot use the rewriting engine. This restriction is + needed for security reasons.
+ +

Here are all possible substitution combinations and their + meanings:

+ +

Inside per-server configuration + (httpd.conf)
+ for request ``GET + /somepath/pathinfo'':

+

+ + + + + +
+
+Given Rule                                      Resulting Substitution
+----------------------------------------------  ----------------------------------
+^/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
+
+
+ +

Inside per-directory configuration for + /somepath
+ (i.e., file .htaccess in dir + /physical/path/to/somepath containing + RewriteBase /somepath)
+ for request ``GET + /somepath/localpath/pathinfo'':

+

+ + + + + +
+
+Given Rule                                      Resulting Substitution
+----------------------------------------------  ----------------------------------
+^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
+
+
+ +

Example:

+ +
+ We want to rewrite URLs of the form + +
+ / Language /~ + Realname /.../ File +
+ into + +
+ /u/ Username /.../ + File . Language +
+ +

We take the rewrite mapfile from above and save it under + /path/to/file/map.txt. Then we only have to + add the following lines to the Apache server configuration + file:

+ +
+
+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
+
+
+
+
+ +
+

Miscellaneous

+
+
+ +

Environment + Variables

+ This module keeps track of two additional (non-standard) + CGI/SSI environment variables named SCRIPT_URL + and SCRIPT_URI. These contain the + logical Web-view to the current resource, while the + standard CGI/SSI variables SCRIPT_NAME and + SCRIPT_FILENAME contain the physical + System-view. + +

Notice: These variables hold the URI/URL as they were + initially requested, i.e., before any + rewriting. This is important because the rewriting process is + primarily used to rewrite logical URLs to physical + pathnames.

+ +

Example:

+ +
+
+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/
+
+
+
+ +

Practical + Solutions

+ We also have an URL + Rewriting Guide 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. +
+
+ +

Apache HTTP Server Version 1.3

+ Index + Home + + + + + + 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 @@ + + + + + + + + + + + Apache module mod_rewrite + + + + +
+ +
+ [APACHE DOCUMENTATION] + +

Apache HTTP Server Version 1.3

+
+ +
+ + +

Module mod_rewrite
+ URL Rewriting Engine

+ +

This module provides a rule-based rewriting engine to + rewrite requested URLs on the fly.

+ +

Status: Extension
+ Source File: + mod_rewrite.c
+ Module Identifier: + rewrite_module
+ Compatibility: Available in + Apache 1.2 and later.

+
+
+ + +

Summary

+ +
+
+
+ ``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.'' + + +
+ -- Brian Behlendorf
+ Apache Group +
+
+
+
+ +
+
+
+ `` Despite the tons of examples and docs, + mod_rewrite is voodoo. Damned cool voodoo, but still + voodoo. '' + +
+ -- Brian Moore
+ bem@news.cmc.net +
+
+
+
+ Welcome to mod_rewrite, the Swiss Army Knife of URL + manipulation! + +

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.

+ +

This module operates on the full URLs (including the + path-info part) both in per-server context + (httpd.conf) and per-directory context + (.htaccess) 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.

+ +

But all this functionality and flexibility has its + drawback: complexity. So don't expect to understand this + entire module in just one day.

+ +

This module was invented and originally written in April + 1996
+ and gifted exclusively to the The Apache Group in July 1997 + by

+ +
+ Ralf S. + Engelschall
+ rse@engelschall.com
+ www.engelschall.com +
+
+ +

Table Of Contents

+ +

Internal Processing

+ + + +

Configuration Directives

+ + + Miscellaneous + + +
+ +
+

Internal + Processing

+
+
+ +

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.

+ +

API + Phases

+ +

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 (.htaccess) have been read, but + before the content handler is activated.

+ +

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:

+ +
    +
  1. 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.
  2. + +
  3. + Unbelievably mod_rewrite provides URL manipulations in + per-directory context, i.e., within + .htaccess files, although these are reached + a very long time after the URLs have been translated to + filenames. It has to be this way because + .htaccess 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 RewriteBase 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. + +

    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.

    +
  4. +
+ +

Don't forget these two points!

+ +

Ruleset + Processing

+ 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. + +

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 (RewriteRule + directives) and when a particular rule matches it optionally + loops through existing corresponding conditions + (RewriteCond 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.

+ +
+ + + + + + + + +
[Needs graphics capability to display]
Figure 1: The + control flow through the rewriting ruleset
+
+ +

As you can see, first the URL is matched against the + Pattern of each rule. When it fails mod_rewrite + immediately stops processing this rule and continues with the + next rule. If the Pattern 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 Substitution 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 TestString by expanding variables, + back-references, map lookups, etc. and then we try + to match CondPattern 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 + Substitution.

+ +

Quoting Special + Characters

+ +

As of Apache 1.3.20, special characters in + TestString and Substitution 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 Substitution string by + using '\$'; this keeps mod_rewrite from trying + to treat it as a backreference.

+ +

Regex + Back-Reference Availability

+ One important thing here has to be remembered: Whenever you + use parentheses in Pattern or in one of the + CondPattern, back-references are internally created + which can be used with the strings $N and + %N (see below). These are available for creating + the strings Substitution and TestString. + Figure 2 shows to which locations the back-references are + transfered for expansion. + +
+ + + + + + + + +
[Needs graphics capability to display]
Figure 2: The + back-reference flow through a rule
+
+ +

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.

+
+ +
+

Configuration Directives

+
+
+ +

RewriteEngine

+ Syntax: RewriteEngine + on|off
+ Default: RewriteEngine + off
+ Context: server config, + virtual host, directory, .htaccess
+ Override: FileInfo
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache + 1.2
+ + +

The RewriteEngine directive enables or + disables the runtime rewriting engine. If it is set to + off this module does no runtime processing at + all. It does not even update the SCRIPT_URx + environment variables.

+ +

Use this directive to disable the module instead of + commenting out all the RewriteRule + directives!

+ +

Note that, by default, rewrite configurations are not + inherited. This means that you need to have a + RewriteEngine on directive for each virtual host + in which you wish to use it.

+
+ +

RewriteOptions

+ Syntax: RewriteOptions + Option
+ Default: RewriteOptions + MaxRedirects=10
+ Context: server config, + virtual host, directory, .htaccess
+ Override: FileInfo
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache + 1.2; MaxRedirects is available in Apache 1.3.28 and + later
+ + +

The RewriteOptions directive sets some + special options for the current per-server or per-directory + configuration. The Option strings can be one of the + following:

+ +
+
inherit
+
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 + .htaccess configuration are inherited.
+ +
MaxRedirects=number
+
In order to prevent endless loops of internal redirects + issued by per-directory RewriteRules, + mod_rewrite 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.
+
+
+ +

RewriteLog

+ Syntax: RewriteLog + file-path
+ Default: None
+ Context: server config, + virtual host
+ Override: Not + applicable
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache + 1.2
+ + +

The RewriteLog 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 + ('/') then it is assumed to be relative to the + Server Root. The directive should occur only once + per server config.

+ + + + + +
Note: To disable the logging of + rewriting actions it is not recommended to set + file-path to /dev/null, because + although the rewriting engine does not then output to a + logfile it still creates the logfile output internally. + This will slow down the server with no advantage + to the administrator! To disable logging either + remove or comment out the RewriteLog + directive or use RewriteLogLevel 0!
+ + + + + +
Security: See the Apache Security + Tips 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.
+ +

Example:

+ +
+
+RewriteLog "/usr/local/var/apache/logs/rewrite.log"
+
+
+
+ +

RewriteLogLevel

+ Syntax: RewriteLogLevel + Level
+ Default: + RewriteLogLevel 0
+ Context: server config, + virtual host
+ Override: Not + applicable
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache + 1.2
+ + +

The RewriteLogLevel 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.

+ +

To disable the logging of rewriting actions simply set + Level to 0. This disables all rewrite action + logs.

+ + + + + +
Notice: Using a high value for + Level will slow down your Apache server + dramatically! Use the rewriting logfile at a + Level greater than 2 only for debugging!
+ +

Example:

+ +
+
+RewriteLogLevel 3
+
+
+
+ +

RewriteLock

+ Syntax: RewriteLock + file-path
+ Default: None
+ Context: server config
+ Override: Not + applicable
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache + 1.3
+ + +

This directive sets the filename for a synchronization + lockfile which mod_rewrite needs to communicate with + RewriteMap programs. 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.

+
+ +

RewriteMap

+ Syntax: RewriteMap + MapName MapType:MapSource
+ Default: not used per + default
+ Context: server config, + virtual host
+ Override: Not + applicable
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache 1.2 + (partially), Apache 1.3
+ + +

The RewriteMap directive defines a + Rewriting Map 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.

+ +

The MapName 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:

+ +
+ ${ MapName : + LookupKey }
+ ${ MapName : + LookupKey | DefaultValue + }
+
+ When such a construct occurs the map MapName is + consulted and the key LookupKey is looked-up. If the + key is found, the map-function construct is substituted by + SubstValue. If the key is not found then it is + substituted by DefaultValue or by the empty string + if no DefaultValue was specified. + +

The following combinations for MapType and + MapSource can be used:

+ + + The RewriteMap directive can occur more than + once. For each mapping-function use one + RewriteMap directive to declare its rewriting + mapfile. While you cannot declare a map in + per-directory context it is of course possible to + use this map in per-directory context. + + + + + +
Note: For plain text and DBM format + files the looked-up keys are cached in-core until the + mtime of the mapfile changes or the server + does a restart. This way you can have map-functions in + rules which are used for every request. + This is no problem, because the external lookup only + happens once!
+
+ +

RewriteBase

+ Syntax: RewriteBase + URL-path
+ Default: default is the + physical directory path
+ Context: directory, + .htaccess
+ Override: + FileInfo
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache + 1.2
+ + +

The RewriteBase directive explicitly sets the + base URL for per-directory rewrites. As you will see below, + RewriteRule can be used in per-directory config + files (.htaccess). There it will act locally, + i.e., 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.

+ +

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. But at most websites URLs are NOT + directly related to physical filename paths, so this + assumption will usually be wrong! There you have to + use the RewriteBase directive to specify the + correct URL-prefix.

+ + + + + +
Notice: If your webserver's URLs are + not directly related to physical file + paths, you have to use RewriteBase in every + .htaccess files where you want to use + RewriteRule directives.
+ +

Example:

+ +
+ Assume the following per-directory config file: + + + + + +
+
+#
+#  /abc/def/.htaccess -- per-dir config file for directory /abc/def
+#  Remember: /abc/def is the physical path of /xyz, i.e., the server
+#            has a 'Alias /xyz /abc/def' directive e.g.
+#
+
+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
+
+
+ +

In the above example, a request to + /xyz/oldstuff.html gets correctly rewritten to + the physical file /abc/def/newstuff.html.

+ + + + + +
+ Note - For Apache + hackers:
+ The following list gives detailed information about + the internal processing steps:
+
+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
+
+
+ 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. +
+
+
+ +

RewriteCond

+ Syntax: RewriteCond + TestString CondPattern
+ Default: None
+ Context: server config, + virtual host, directory, .htaccess
+ Override: + FileInfo
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache 1.2 + (partially), Apache 1.3
+ + +

The RewriteCond directive defines a rule + condition. Precede a RewriteRule directive with + one or more RewriteCond directives. The + following rewriting rule is only used if its pattern matches + the current state of the URI and if these + additional conditions apply too.

+ +

TestString is a string which can contains the + following expanded constructs in addition to plain text:

+ + + +

Special Notes:

+ +
    +
  1. The variables SCRIPT_FILENAME and REQUEST_FILENAME + contain the same value, i.e., the value of the + filename field of the internal + request_rec 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 + uri field of request_rec).
  2. + +
  3. There is the special format: + %{ENV:variable} where variable can be + any environment variable. This is looked-up via internal + Apache structures and (if not found there) via + getenv() from the Apache server process.
  4. + +
  5. There is the special format: + %{HTTP:header} where header can be + any HTTP MIME-header name. This is looked-up from the HTTP + request. Example: %{HTTP:Proxy-Connection} is + the value of the HTTP header + ``Proxy-Connection:''.
  6. + +
  7. There is the special format + %{LA-U:variable} for look-aheads which perform + an internal (URL-based) sub-request to determine the final + value of variable. 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 + REMOTE_USER variable from within the + per-server context (httpd.conf file) you have + to use %{LA-U:REMOTE_USER} because this + variable is set by the authorization phases which come + after the URL translation phase where mod_rewrite + operates. On the other hand, because mod_rewrite implements + its per-directory context (.htaccess file) via + the Fixup phase of the API and because the authorization + phases come before this phase, you just can use + %{REMOTE_USER} there.
  8. + +
  9. There is the special format: + %{LA-F:variable} which performs an internal + (filename-based) sub-request to determine the final value + of variable. Most of the time this is the same as + LA-U above.
  10. +
+ +

CondPattern is the condition pattern, + i.e., a regular expression which is applied to the + current instance of the TestString, i.e., + TestString is evaluated and then matched against + CondPattern.

+ +

Remember: CondPattern is a + standard Extended Regular Expression with some + additions:

+ +
    +
  1. You can prefix the pattern string with a + '!' character (exclamation mark) to specify a + non-matching pattern.
  2. + +
  3. + There are some special variants of CondPatterns. + Instead of real regular expression strings you can also + use one of the following: + +
      +
    • '<CondPattern' (is lexically + lower)
      + Treats the CondPattern as a plain string and + compares it lexically to TestString. True if + TestString is lexically lower than + CondPattern.
    • + +
    • '>CondPattern' (is lexically + greater)
      + Treats the CondPattern as a plain string and + compares it lexically to TestString. True if + TestString is lexically greater than + CondPattern.
    • + +
    • '=CondPattern' (is lexically + equal)
      + Treats the CondPattern as a plain string and + compares it lexically to TestString. True if + TestString is lexically equal to + CondPattern, i.e the two strings are exactly + equal (character by character). If CondPattern + is just "" (two quotation marks) this + compares TestString to the empty string.
    • + +
    • '-d' (is + directory)
      + Treats the TestString as a pathname and tests + if it exists and is a directory.
    • + +
    • '-f' (is regular + file)
      + Treats the TestString as a pathname and tests + if it exists and is a regular file.
    • + +
    • '-s' (is regular file with + size)
      + Treats the TestString as a pathname and tests + if it exists and is a regular file with size greater + than zero.
    • + +
    • '-l' (is symbolic + link)
      + Treats the TestString as a pathname and tests + if it exists and is a symbolic link.
    • + +
    • '-F' (is existing file via + subrequest)
      + Checks if TestString 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!
    • + +
    • '-U' (is existing URL via + subrequest)
      + Checks if TestString 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!
    • +
    + + + + + +
    Notice: All of these tests can + also be prefixed by an exclamation mark ('!') to + negate their meaning.
    +
  4. +
+ +

Additionally you can set special flags for + CondPattern by appending

+ +
+ [flags] +
+ as the third argument to the RewriteCond + directive. Flags is a comma-separated list of the + following flags: + + + +

Example:

+ +
+ To rewrite the Homepage of a site according to the + ``User-Agent:'' header of the request, you can + use the following: + +
+
+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]
+
+
+ Interpretation: If you use Netscape Navigator as your + browser (which identifies itself as 'Mozilla'), then you + get the max homepage, which includes Frames, etc. + If you use the Lynx browser (which is Terminal-based), then + you get the min homepage, which contains no images, no + tables, etc. If you use any other browser you get + the standard homepage. +
+
+ +

RewriteRule

+ Syntax: RewriteRule + Pattern Substitution
+ Default: None
+ Context: server config, + virtual host, directory, .htaccess
+ Override: + FileInfo
+ Status: Extension
+ Module: mod_rewrite.c
+ Compatibility: Apache 1.2 + (partially), Apache 1.3
+ + +

The RewriteRule directive is the real + rewriting workhorse. The directive can occur more than once. + Each directive then defines one single rewriting rule. The + definition order of these rules is + important, because this order is used when + applying the rules at run-time.

+ +

Pattern can + be (for Apache 1.1.x a System V8 and for Apache 1.2.x and + later a POSIX) regular + expression 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.

+ +

Some hints about the syntax of regular expressions:

+ + + + + +
+
+Text:
+  .           Any single character
+  [chars]     Character class: One  of chars
+  [^chars]    Character class: None of chars
+  text1|text2 Alternative: text1 or text2
+
+Quantifiers:
+  ?           0 or 1 of the preceding text
+  *           0 or N of the preceding text (N > 0)
+  +           1 or N of the preceding text (N > 1)
+
+Grouping:
+  (text)      Grouping of text
+              (either to set the borders of an alternative or
+              for making backreferences where the Nth group can 
+              be used on the RHS of a RewriteRule with $N)
+
+Anchors:
+  ^           Start of line anchor
+  $           End   of line anchor
+
+Escaping:
+  \char       escape that particular char
+              (for instance to specify the chars ".[]()" etc.)
+
+
+ +

For more information about regular expressions either have + a look at your local regex(3) manpage or its + src/regex/regex.3 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, etc.) have a look at the + following dedicated book on this topic:

+ +
+ Mastering Regular Expressions
+ Jeffrey E.F. Friedl
+ Nutshell Handbook Series
+ O'Reilly & Associates, Inc. 1997
+ ISBN 1-56592-257-3
+
+ +

Additionally in mod_rewrite the NOT character + ('!') is a possible pattern prefix. This gives + you the ability to negate a pattern; to say, for instance: + ``if the current URL does NOT match this + pattern''. This can be used for exceptional cases, where + it is easier to match the negative pattern, or as a last + default rule.

+ + + + + +
Notice: 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 $N in the substitution + string!
+ +

Substitution of a + rewriting rule is the string which is substituted for (or + replaces) the original URL for which Pattern + matched. Beside plain text you can use

+ +
    +
  1. back-references $N to the RewriteRule + pattern
  2. + +
  3. back-references %N to the last matched + RewriteCond pattern
  4. + +
  5. server-variables as in rule condition test-strings + (%{VARNAME})
  6. + +
  7. mapping-function calls + (${mapname:key|default})
  8. +
+ Back-references are $N + (N=0..9) identifiers which will be replaced + by the contents of the Nth group of the + matched Pattern. The server-variables are the same + as for the TestString of a RewriteCond + directive. The mapping-functions come from the + RewriteMap directive and are explained there. + These three types of variables are expanded in the order of + the above list. + +

As already mentioned above, all the rewriting rules are + applied to the Substitution (in the order of + definition in the config file). The URL is completely + replaced by the Substitution and the + rewriting process goes on until there are no more rules + unless explicitly terminated by a + L flag - see below.

+ +

There is a special substitution string named + '-' which means: NO + substitution! Sounds silly? No, it is useful to + provide rewriting rules which only match + some URLs but do no substitution, e.g., in + conjunction with the C (chain) flag to be + able to have more than one pattern to be applied before a + substitution occurs.

+ +

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.

+ + + + + +
Note: There is a special feature: + When you prefix a substitution field with + http://thishost[:thisport] + then mod_rewrite 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.
+ + + + + +
Remember: An unconditional external + redirect to your own server will not work with the prefix + http://thishost because of this feature. To + achieve such a self-redirect, you have to use the + R-flag (see below).
+ +

Additionally you can set special flags for + Substitution by appending

+ +
+ [flags] +
+ as the third argument to the RewriteRule + directive. Flags is a comma-separated list of the + following flags: + + + + + + + +
+ Note: Never forget that + Pattern is applied to a complete URL in + per-server configuration files. But in + per-directory configuration files, the per-directory + prefix (which always is the same for a specific + directory!) is automatically removed for the + pattern matching and automatically added after + the substitution has been done. 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. + +

There is one exception: If a substitution string + starts with ``http://'' then the directory + prefix will not be added and an + external redirect or proxy throughput (if flag + P is used!) is forced!

+
+ + + + + +
Note: To enable the rewriting engine + for per-directory configuration files you need to set + ``RewriteEngine On'' in these files + and ``Options + FollowSymLinks'' must be enabled. If your + administrator has disabled override of + FollowSymLinks for a user's directory, then + you cannot use the rewriting engine. This restriction is + needed for security reasons.
+ +

Here are all possible substitution combinations and their + meanings:

+ +

Inside per-server configuration + (httpd.conf)
+ for request ``GET + /somepath/pathinfo'':

+

+ + + + + +
+
+Given Rule                                      Resulting Substitution
+----------------------------------------------  ----------------------------------
+^/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
+
+
+ +

Inside per-directory configuration for + /somepath
+ (i.e., file .htaccess in dir + /physical/path/to/somepath containing + RewriteBase /somepath)
+ for request ``GET + /somepath/localpath/pathinfo'':

+

+ + + + + +
+
+Given Rule                                      Resulting Substitution
+----------------------------------------------  ----------------------------------
+^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
+
+
+ +

Example:

+ +
+ We want to rewrite URLs of the form + +
+ / Language /~ + Realname /.../ File +
+ into + +
+ /u/ Username /.../ + File . Language +
+ +

We take the rewrite mapfile from above and save it under + /path/to/file/map.txt. Then we only have to + add the following lines to the Apache server configuration + file:

+ +
+
+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
+
+
+
+
+ +
+

Miscellaneous

+
+
+ +

Environment + Variables

+ This module keeps track of two additional (non-standard) + CGI/SSI environment variables named SCRIPT_URL + and SCRIPT_URI. These contain the + logical Web-view to the current resource, while the + standard CGI/SSI variables SCRIPT_NAME and + SCRIPT_FILENAME contain the physical + System-view. + +

Notice: These variables hold the URI/URL as they were + initially requested, i.e., before any + rewriting. This is important because the rewriting process is + primarily used to rewrite logical URLs to physical + pathnames.

+ +

Example:

+ +
+
+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/
+
+
+
+ +

Practical + Solutions

+ We also have an URL + Rewriting Guide 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. +
+
+ +

Apache HTTP Server Version 1.3

+ Index + Home + + + + + + + + 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 @@ + + + + + + + + + Apache module mod_rewrite + + + + + +
+ +
+ [APACHE DOCUMENTATION] + +

Apache HTTP Server Version 1.3

+
+ +
+ +

mod_rewrite $B%b%8%e!<%k(B
+ URL $B=q$-49$(%(%s%8%s(B

+ +

$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 +

+ +

$B%9%F!<%?%9(B: Extension
+ $B%=!<%9%U%!%$%k(B: + mod_rewrite.c
+ $B%b%8%e!<%k<1JL;R(B: + rewrite_module
+ $B8_49@-(B: Apache 1.2 $B0J9_$G;HMQ2DG=(B

+
+
+ +

$B35MW(B

+ +
+
+
+ `` 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'' + +
+ -- Brian Behlendorf
+ Apache Group +
+
+
+
+ +
+
+
+ `` $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'' + +
+ -- Brian Moore
+ bem@news.cmc.net +
+
+
+
+ URL $B$rA`:n$9$k$?$a$N%9%$%9@=$N%"!<%_!<%J%$%U!"(Bmod_rewrite + $B$X$h$&$3$=(B! + +

$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!"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 + +

$B$3$N%b%8%e!<%k$O!"%5!<%PC10L$N%3%s%F%-%9%H(B + (httpd.conf) $B$*$h$S%G%#%l%/%H%jC10L$N%3%s%F%-%9%H(B + (.htaccess) $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! + +

$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 +

+ +

$B$3$N%b%8%e!<%k$O(B 1996 $BG/$N(B 4 $B7n$K(B

+ +
+ Ralf S. + Engelschall
+ rse@engelschall.com
+ www.engelschall.com +
+ +

$B$i$K$h$j9M0F$5$l$F%*%j%8%J%k$,=q$+$l!"(B
+ 1997 $BG/$N(B 7 $B7n$K!"(BThe Apache Group + $B$KBP$7$FFH@jE*$KB#Dh$5$l$^$7$?!#(B

+
+ +

$BL\ + +

$BFbIt=hM}(B

+ + + +

$B@_Dj%G%#%l%/%F%#%V(B

+ + + $B$=$NB>(B + + +
+ +
+

$BFbIt=hM}(B

+
+
+ +

$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 +

+ +

API $B%U%'!<%:(B

+ +

$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 (.htaccess) + $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 +

+ +

$B$=$7$F!"$"$k%j%/%(%9%H$,F~$C$FMh$F!"(BApache $B$,$3$l$KBP1~$9$k%5!<%P(B + ($B/$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:

+ +
    +
  1. 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$-;ve$N$3$H$r9T$$$^$9!#(B
  2. + +
  3. 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$B$9$J$o$A(B + .htaccess $B%U%!%$%k$NCf$G(B URL + $BA`:n$r9T$($k$h$&$K$J$C$F$$$9!#(B.htaccess + $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 + RewriteBase $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 + +

    $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 +

    +
  4. +
+ +

$B$3$l$iFs$D$NE@$rK:$l$J$$$G$/$@$5$$(B!

+ +

$B%k!<%k%;%C%H=hM}(B

+ $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 + +

$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 + (RewriteRule$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 (RewriteCond$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

+ +
+ + + + + + + + +
[$BI=<($9$k$K$O%0%i%U%#%C%/5!G=$,I,MW$G$9(B]
$B?^(B 1: + $B=q$-49$(%k!<%k%;%C%H$K$*$1$k@)8f%U%m!<(B
+
+ +

$B$b$&$*J,$+$j$N$h$&$K!"$^$:(B URL $B$r3F%k!<%k$N(B Pattern + $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$FPattern $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 Substitution $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$B$J$I(B$B$7$F(B$B%F%9%HJ8;zNs(B + $B$r@8@.$7!"$=$l$KBP$7$F(B$B>r7o%Q%?!<%s(B$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 + $Br7o$,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 Substitution + $BJ8;zNs$KCV49$5$l!"=hM}$,7QB3$5$l$^$9!#(B

+ +

$BFC

+ +

Apache 1.3.20 $B$G$O!"(B$B%F%9%HJ8;zNs(B$B$H(B Substitution + $BJ8;zNs$NCf$NFCA0$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;}$DFCC$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$BCV49BP>](B$BJ8;zNs$NCf$G$b(B '\$' + $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 +

+ +

$B@55,I=8=$N8eJ};2>H$r;H$&(B

+ $B$3$3$G$R$H$D3P$($F$*$$$FM_$7$$$3$H$,$"$j$^$9(B: Pattern + $B$NCf$d(B CondPattern $B$N$&$A$N$I$3$+$G3g8L$r;H$($P!"J8;zNs(B + $N $B$H(B %N + $B$G;H$($k8eJ};2>H$,FbItE*$K@8@.$5$l$^$9(B ($B8e=R(B)$B!#$3$l$i$O(B + Substitution + $BJ8;zNs$d(B$B%F%9%HJ8;zNs(B$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 + +
+ + + + + + + + +
[$BI=<($9$k$K$O%0%i%U%#%C%/5!G=$,I,MW$G$9(B]
$B?^(B 2: + $B%k!<%k$rDL$7$?8eJ};2>H$NN.$l(B
+
+ +

$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

+
+ +
+

$B@_Dj%G%#%l%/%F%#%V(B

+
+
+ +

RewriteEngine

+ $B=q<0(B: RewriteEngine + on|off
+ $B%G%U%)%k%H(B: RewriteEngine + off
+ $B%3%s%F%-%9%H(B: $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H!"%G%#%l%/%H%j!"(B.htaccess
+ $B%*!<%P!<%i%$%I(B: FileInfo
+ $B%9%F!<%?%9(B: Extension
+ $B%b%8%e!<%k(B: mod_rewrite.c
+ $B8_49@-(B: Apache + 1.2
+ +

RewriteEngine $B%G%#%l%/%F%#%V$r;H$&$H!"(B + $Boff $B$K@_Dj$5$l$F$$$k$H!"$3$N%b%8%e!<%k$OSCRIPT_URx + $B4D6-JQ?t$N99?7$5$($b$7$J$/$J$j$^$9!#(B

+ +

RewriteRule $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

+ +

$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 + RewriteEngine on + $B%G%#%l%/%F%#%V$r=q$+$J$1$l$P$$$1$J$$$H$$$&$3$H$G$9!#(B

+
+ +

RewriteOptions

+ $B=q<0(B: RewriteOptions + $B%*%W%7%g%s(B
+ $B%G%U%)%k%H(B: RewriteOptions + MaxRedirects=10
+ $B%3%s%F%-%9%H(B: $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H!"%G%#%l%/%H%j!"(B.htaccess
+ $B%*!<%P!<%i%$%I(B: FileInfo
+ $B%9%F!<%?%9(B: Extension
+ $B%b%8%e!<%k(B: mod_rewrite.c
+ $B8_49@-(B: Apache + 1.2$B!#(BMaxRedirects $B$O(B Apache 1.3.28 $B0J9_$G;HMQ2DG=(B
+ +

RewriteOptions $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 + Option $BJ8;zNs$O0J2<$N$$$:$l$+$G$9(B:

+ +
+
inherit
+
$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 + .htaccess + $B@_Dj$K5-=R$5$l$F$$$k>r7o$d%k!<%k$,7Q>5$5$l$k$3$H$K$J$j$^$9!#(B
+ +
MaxRedirects=number
+
$B%G%#%l%/%H%jKh$N(B RewriteOptions $B$K$h$kFbIt%j%@%$%l%/%H$N(B + $BL58B%k!<%W$rKI$0$?$a$K!"(Bmod_rewrite $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
+
+
+ +

RewriteLog

+ $B=q<0(B: RewriteLog + file-path
+ $B%G%U%)%k%H(B: $B$J$7(B
+ $B%3%s%F%-%9%H(B: $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H(B
+ $B%*!<%P!<%i%$%I(B: $BE,MQIT2D(B
+ $B%9%F!<%?%9(B: Extension
+ $B%b%8%e!<%k(B: mod_rewrite.c
+ $B8_49@-(B: Apache + 1.2
+ + $B!!(B

RewriteLog $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 + ('/') $B$G;O$^$i$J$$>l9g$O(B Server Root + $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

+ + + + + +
$BCm0U(B: + $B=q$-49$(F0:n$N%m%.%s%0$rM^@)$9$k$?$a$K(B file-path $B$r(B + /dev/null $B$K$9$k$N$O$*4+$a$G$-$^$;$s!#$3$l$O!"(B + $B=q$-49$(%(%s%8%s$O$B$3$l$O4IM} + $B%m%.%s%0$rM^;_$9$k>l9g$O(B RewriteLog + $B%G%#%l%/%F%#%V$r%3%a%s%H%"%&%H$9$k$+!"(B + RewriteLogLevel 0 $B$r;H$&$h$&$K$7$F$/$@$5$$(B!
+ + + + + +
$B%;%-%e%j%F%#(B: + $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 + Apache $B$N%;%-%e%j%F%#$N(B + $B$3$D(B $B%I%-%e%a%s%H$r$4Mw$/$@$5$$!#(B
+ +

$BNc(B:

+ +
+
+RewriteLog "/usr/local/var/apache/logs/rewrite.log"
+
+
+
+ +

RewriteLogLevel

+ $B=q<0(B: RewriteLogLevel + Level
+ $B%G%U%)%k%H(B: + RewriteLogLevel 0
+ $B%3%s%F%-%9%H(B: $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H(B
+ $B%*!<%P!<%i%$%I(B: $BE,MQIT2D(B
+ $B%9%F!<%?%9(B: Extension
+ $B%b%8%e!<%k(B: mod_rewrite.c
+ $B8_49@-(B: Apache + 1.2
+ +

RewriteLogLevel $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;ve$[$H$s$I$9$Y$F$NF0:n$K$D$$$F%m%0$,<}=8$5$l$^$9!#(B

+ +

$B=q$-49$($N%m%0$rLevel $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 +

+ + + + + +
$BCm0U(B: Level + $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 Level $B$K(B 2 + $B0J>e$NCM$r;XDj$9$k$N$O%G%P%C%0;~$N$_$K$7$F$*$$$F$/$@$5$$(B!
+ +

$BNc(B:

+ +
+
+RewriteLogLevel 3
+
+
+
+ +

RewriteLock

+ $B=q<0(B: RewriteLock + file-path
+ $B%G%U%)%k%H(B: $B$J$7(B
+ $B%3%s%F%-%9%H(B: $B%5!<%P@_Dj%U%!%$%k(B
+ $B%*!<%P!<%i%$%I(B: $BE,MQIT2D(B
+ $B%9%F!<%?%9(B: Extension
+ $B%b%8%e!<%k(B: mod_rewrite.c
+ $B8_49@-(B: Apache + 1.3
+ +

$B$3$N%G%#%l%/%F%#%V$O!"(Bmod_rewrite $B$,(B RewriteMap + $B%W%m%0%i%`(B$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

+
+ +

RewriteMap

+ $B=q<0(B: RewriteMap + MapName MapType:MapSource
+ $B%G%U%)%k%H(B:$B%G%U%)%k%H$G$O;HMQ$5$l$J$$(B +
+ $B%3%s%F%-%9%H(B: $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H(B
+ $B%*!<%P!<%i%$%I(B: $BE,MQIT2D(B
+ $B%9%F!<%?%9(B: Extension
+ $B%b%8%e!<%k(B: mod_rewrite.c
+ $B8_49@-(B: Apache 1.2 + ($B0lIt$N$_(B), Apache 1.3
+ + +

RewriteMap $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 + $B=q$-49$(%^%C%W(B$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

+ +

MapName + $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

+ +
+ ${ MapName : + LookupKey }
+ ${ MapName : + LookupKey | DefaultValue + }
+
+ $B$3$N$h$&$J=q<0$,8=$l$k$H!"(BMapName $B$H$$$&L>A0$N%^%C%W$NCf$N%-!<(B + LookupKey $B$,8!:w$5$l$^$9!#(B + $B%-!<$,8+$D$+$l$P!"$3$N%^%C%W4X?t$N=q<0$NItJ,$O(B SubstValue + $B$K$h$jCV49$5$l$^$9!#%-!<$,8+$D$+$i$J$$>l9g!"(B + DefaultValue $B$,$"$l$P$=$l$GCV49$5$l!"(BDefaultValue + $B$,;XDj$5$l$F$$$J$1$l$P6uJ8;zNs$KCV49$5$l$^$9!#(B + +

$B0J2<$N$h$&$J(B MapType $B$H(B MapSource + $B$r;H$C$?AH$_9g$o$;$r;HMQ$G$-$^$9(B:

+ +
    +
  • + $BI8=`$N%W%l!<%s%F%-%9%H(B
    + MapType: txt, MapSource: + Unix $B%U%!%$%k%7%9%F%`$NM-8z$JDL>o%U%!%$%k$X$N%Q%9(B + +

    $B$3$l$OI8=`$N=q$-49$(%^%C%W5!G=$G$9!#(B + MapSource $B$O6uGr9T$d%3%a%s%H9T(B($B9TF,$,(B + '#' $BJ8;z$G;O$^$k9T(B)$B!" + +

    + MatchingKey + SubstValue +
    + +

    $BNc(B:

    + + + + + +
    +
    +##
    +##  map.txt -- rewriting map
    +##
    +
    +Ralf.S.Engelschall    rse   # Bastard Operator From Hell
    +Mr.Joe.Average        joe   # Mr. Average
    +
    +
    + + + + + +
    +
    +RewriteMap real-to-user txt:/path/to/file/map.txt
    +
    +
    +
  • + +
  • + $B%i%s%@%`$J%W%l!<%s%F%-%9%H(B
    + MapType: rnd, MapSource: + Unix $B%U%!%$%k%7%9%F%`$NM-8z$JDL>o%U%!%$%k$X$N%Q%9(B + +

    $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 ``|'' $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$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:

    + + + + + +
    +
    +##
    +##  map.txt -- rewriting map
    +##
    +
    +static   www1|www2|www3|www4
    +dynamic  www5|www6
    +
    +
    + + + + + +
    +
    +RewriteMap servers rnd:/path/to/file/map.txt
    +
    +
    +
  • + +
  • + $B%O%C%7%e%U%!%$%k(B
    + MapType: dbm, MapSource: + Unix $B%U%!%$%k%7%9%F%`$NM-8z$JDL>o%U%!%$%k$X$N%Q%9(B + +

    $B%U%!%$%k$NFbMF$N0UL#$O(B$B%W%l!<%s%F%-%9%H(B$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

    + + + + + +
    +
    +#!/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);
    +
    +
    + + + + + +
    +
    +$ txt2dbm map.txt map.db
    +
    +
    +
  • + +
  • + $BFbIt4X?t(B
    + MapType: int, MapSource: $BFbIt(B Apache $B4X?t(B + +

    $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

    + +
      +
    • toupper:
      + $B8+$D$+$C$?%-!<$r$9$Y$FBgJ8;z$KJQ49$9$k!#(B
    • + +
    • tolower:
      + $B8+$D$+$C$?%-!<$r$9$Y$F>.J8;z$KJQ49$9$k!#(B
    • + +
    • escape:
      + $B8+$D$+$C$?%-!<$NCf$NFC + +
    • unescape:
      + $B8+$D$+$C$?%-!<$NCf$N(B 16 $B?J%(%s%3!<%G%#%s%0$rFC +
    +
  • + +
  • + $B30It$N=q$-49$(%W%m%0%i%`(B
    + MapType: prg, MapSource: + Unix $B%U%!%$%k%7%9%F%`$NM-8z$JDL>o%U%!%$%k$X$N%Q%9(B + +

    $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$B$9$J$o$A(B$B%*%V%8%'%/%H%3!<%I!"#!/path/to/interpreter' + $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

    + +

    $B$3$N%W%m%0%i%`$O(B Apache $B%5!<%P$N5/F0;~$K0lEY$@$15/F0$5$l!"(B + stdin $B$*$h$S(B stdout + $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 + stdin $B$+$i$B$9$J$o$A(B$B!"M?$($i$l$?%-!<$KBP1~$9$kCM$,$J$$(B)$B!"(B + 4 $BJ8;z$NJ8;zNs(B ``NULL'' $B$rJV$5$J$1$l$P$J$j$^$;$s!#(B + 1:1 $B$N%^%C%W(B($B$9$J$o$A(B$B%-!<(B == $BCM(B) + $B$r + + + + + +
    +
    +#!/usr/bin/perl
    +$| = 1;
    +while (<STDIN>) {
    +    # ...put here any transformations or lookups...
    +    print $_;
    +}
    +
    +
    + +

    $B$7$+$7!"==J,$K5$$r$D$1$F$[$7$$$3$H$,$"$j$^$9(B:
    +

    + +
      +
    1. ``Keep it simple, stupid + ($BC1=c$J$^$^$K$7$F$*$1!"GO'' (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
    2. + +
    3. $B$"$j$,$A$J4V0c$$$H$7$F$O(B: stdout + $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 ``$|=1'' + $B$H$d$C$F$k$s$G$9!D!#(B
    4. + +
    5. RewriteLock + $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 +
    +
  • +
+ RewriteMap $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 RewriteMap + $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$B@k8@$9$k(B + $B$3$H$O$G$-$^$;$s$,!"%G%#%l%/%H%j$N%3%s%F%-%9%H$G$3$N%^%C%W$r(B + $B;H$&(B$B$3$H$O$b$A$m$s2DG=$G$9!#(B + + + + + +
$BCm0U(B: $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 mtime + $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$BKh2s$N(B$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
+
+ +

RewriteBase

+ $B=q<0(B: RewriteBase + URL-path
+ $B%G%U%)%k%H(B: $B%G%U%)%k%H$OJ*M}(B + $B%G%#%l%/%H%j$N%Q%9(B
+ $B%3%s%F%-%9%H(B: $B%G%#%l%/%H%j(B, .htaccess
+ $B%*!<%P!<%i%$%I(B: + FileInfo
+ $B%9%F!<%?%9(B: Extension
+ $B%b%8%e!<%k(B: mod_rewrite.c
+ $B8_49@-(B: Apache + 1.2
+ +

RewriteBase + $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 + RewriteRule $B$O%G%#%l%/%H%j$4$H$N@_Dj%U%!%$%k(B + (.htaccess) $B$G;H$($^$9!#(B + $B$=$3$G$O!"$3$l$O%m!<%+%k$K?6$kIq$$$^$9!#(B$B$9$J$o$A(B$B!"(B + $B$3$N=hM}CJ3,$G$O%m!<%+%k%G%#%l%/%H%j$N@\F,<-$, + +

$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,<-!"$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$B!#(B + $B$=$N$?$a!"(BRewriteBase $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

+ + + + + +
$BCm0U(B: $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$B$J$1(B$B$l$P!"(B + RewriteRule + $B%G%#%l%/%F%#%V$r;H$*$&$H$7$F$$$k%G%#%l%/%H%j$9$Y$F$K$*$$$F!"3F(B + .htaccess $B%U%!%$%k$G(B RewriteBase + $B%G%#%l%/%F%#%V$r;H$o$J$1$l$P$J$j$^$;$s!#(B
+ +

$BNc(B:

+ +
+ $B0J2<$O!"%G%#%l%/%H%j$4$H$N@_Dj%U%!%$%k$@$H;W$C$F$/$@$5$$!'(B + + + + + +
+
+#
+#  /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$B$9$J$o$A(B$B%5!<%P$K$O(B
+#       'Alias /xyz /abc/def' $B$H$$$C$?(B$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
+
+
+ +

$B>e5-$NNc$G$O!"(B/xyz/oldstuff.html + $B$X$N%j%/%(%9%H$GJ*M}%U%!%$%k(B /abc/def/newstuff.html + $B$X$N@5$7$$=q$-49$(A`:n$,9T$o$l$^$9!#(B

+ + + + + +
+ Apache + $B%O%C%+!<$N$?$a$NCm
+ $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:
+
+$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
+
+
+ $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$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 +
+
+
+ +

RewriteCond

+ $B=q<0(B: RewriteCond + TestString CondPatter
+ $B%G%U%)%k%H(B: $B$J$7(B
+ $B%3%s%F%-%9%H(B: $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H!"%G%#%l%/%H%j!"(B.htaccess
+ $B%*!<%P!<%i%$%I(B: + FileInfo
+ $B%9%F!<%?%9(B: Extension
+ $B%b%8%e!<%k(B: mod_rewrite.c
+ $B8_49@-(B: Apache 1.2 + ($BItJ,E*$K(B), Apache 1.3
+ + +

RewriteCond $B%G%#%l%/%F%#%V$O%k!<%k>r7o$rDj5A$7$^$9!#(B + RewriteRule $B%G%#%l%/%F%#%V$NA0$K0l$D0J>e$N(B + RewriteCond $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$B$+$D(B$B$3$l$i$NDI2C>r7o$,(B + $BE,MQ$5$l$k>l9g$K$N$_;H$o$l$^$9!#(B

+ +

TestString$B$OJ8;zNs$G$"$j!"%W%l!<%s%F%-%9%H$K2C$(!"(B + $B0J2<$N3HD%9=B$$r;}$D$3$H$,$G$-$^$9(B:

+ +
    +
  • + RewriteRule $B8eJ};2>H(B: + $B$3$N=q<0$G!"8eJ};2>H$rI=$7$^$9!#(B + +
    + $N +
    + (0 <= N <= 9) $B$3$l$O!"BP1~$9$k(B RewriteRule + $B%G%#%l%/%F%#%V(B($B8=:_$N(BRewriteCond + $B%G%#%l%/%F%#%V$N%V%m%C%/$N + +
  • + RewriteCond $B8eJ};2>H(B: + $B$3$N=q<0$G!"8eJ};2>H$rI=$7$^$9!#(B + +
    + %N +
    + (1 <= N <= 9) + $B$3$l$O!"8=:_$N>r7o%V%m%C%/$NCf$G(BRewriteCond $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 +
  • + +
  • + RewriteMap $B3HD%(B: + $B$3$N=q<0$G!"3HD%$rI=$7$^$9!#(B + +
    + ${mapname:key|default} +
    + $B>\:Y$O(B RewriteMap + $B$N%I%-%e%a%s%H(B$B$r;2>H$N$3$H!#(B +
  • + +
  • + $B%5!<%PJQ?t(B: $B0J2<$OJQ?t$rI=$7$^$9!#(B + +
    + %{ $BJQ?tL>(B + } +
    + $BJQ?tL>(B$B$O0J2<$N0lMw$K$"$kJ8;zNs$N$$$:$l$+$G$9(B: + + + + + + + + + + + + + + + +
    + HTTP $B%X%C%@(B: + +

    HTTP_USER_AGENT
    + HTTP_REFERER
    + HTTP_COOKIE
    + HTTP_FORWARDED
    + HTTP_HOST
    + HTTP_PROXY_CONNECTION
    + HTTP_ACCEPT
    +

    +
    + $B%3%M%/%7%g%s(B & $B%j%/%(%9%H(B: + +

    REMOTE_ADDR
    + REMOTE_HOST
    + REMOTE_USER
    + REMOTE_IDENT
    + REQUEST_METHOD
    + SCRIPT_FILENAME
    + PATH_INFO
    + QUERY_STRING
    + AUTH_TYPE
    +

    +
    + $B%5!<%PFbItJQ?t(B: + +

    DOCUMENT_ROOT
    + SERVER_ADMIN
    + SERVER_NAME
    + SERVER_ADDR
    + SERVER_PORT
    + SERVER_PROTOCOL
    + SERVER_SOFTWARE
    +

    +
    + $B%7%9%F%`4XO"(B: + +

    TIME_YEAR
    + TIME_MON
    + TIME_DAY
    + TIME_HOUR
    + TIME_MIN
    + TIME_SEC
    + TIME_WDAY
    + TIME
    +

    +
    + $BFC + +

    API_VERSION
    + THE_REQUEST
    + REQUEST_URI
    + REQUEST_FILENAME
    + IS_SUBREQ
    +

    +
    + + + + + +
    +

    $BCm0U(B: + $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 + struct tm $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:

    + +
    +
    IS_SUBREQ
    + +
    $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
    + +
    API_VERSION
    + +
    $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 + +
    THE_REQUEST
    + +
    $B%V%i%&%6$+$i%5!<%P$KAw$i$l$?(B HTTP + $B%j%/%(%9%H$N40A4$J$b$N(B($BNc$($P!"(B + "GET /index.html HTTP/1.1")$B!#(B + $B$3$l$K$O!"%V%i%&%6$+$iAw$i$l$?DI2C%X%C%@$O0l@Z4^$_$^$;$s!#(B +
    + +
    REQUEST_URI
    + +
    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
    + +
    REQUEST_FILENAME
    + +
    $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
    +
    +
    +
  • +
+ +

$B9MN8;v9`(B:

+ +
    +
  1. SCRIPT_FILENAME $B$*$h$S(B REQUEST_FILENAME $B$K$OF1$8L>A0!"(B + $B$9$J$o$A(B$B!"(BApache $B%5!<%P$N(B request_rec + $BFbIt9=B$BN$NCf$N(B filename + $B%U%#!<%k%I$NCM$,F~$C$F$$$^$9!#A0$G$"$k$N$KBP$7!"8erequest_rec + $B%U%#!<%k%I$N(B uri $B$NCM$,F~$C$F$$$k(B)REQUEST_URI + $B$KBP1~$9$k$b$N$G$9!#(B
  2. + +
  3. $BJQ?t(B$B$KG$0U$N4D6-JQ?t$r;XDj$G$-$kFCJL$J=q<0(B + %{ENV:$BJQ?t(B} + $B$,$"$j$^$9!#$3$l$O(B Apache + $B$NFbIt9=B$BNgetenv() + $B$rDL$7$F8!:w$5$l$^$9!#(B
  4. + +
  5. + $B%X%C%@(B$B$KG$0U$N(B HTTP MIME $B%X%C%@L>$r;XDj$G$-$kFCJL$J=q<0(B + %{HTTP:$B%X%C%@(B}$B$,$"$j$^$9!#$3$l$O(B + HTTP $B%j%/%(%9%H$+$i8!:w$5$l$^$9!#(B + $BNc(B: %{HTTP:Proxy-Connection} $B$O(B HTTP $B%X%C%@$N(B + ``Proxy-Connection:'' $B$NCM$G$9!#(B
  6. + +
  7. $BA0J};2>H$r9T$J$C$FFbIt$N(B(URL $B%Y!<%9$N(B) + $B%5%V%j%/%(%9%H$r$BJQ?t(B$B$N:G=*CM$r7hDj$9$kFCJL$J=q<0(B + %{LA-U:$BJQ?t(B} $B$,$"$j$^$9!#(B + $Bl9g$K;HMQ$7$^$9!#Nc$($P!"%5!<%PC10L$N%3%s%F%-%9%H(B + (httpd.conf $B%U%!%$%k(B) $B$G(B REMOTE_USER + $BJQ?t$K$7$?$,$C$F=q$-49$($r9T$$$?$$>l9g$K$O!"(B + %{LA-U:REMOTE_USER} + $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$B8e(B$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 + (.htaccess $B%U%!%$%k(B) $B$G$O!"(Bmod_rewrite $B$O(B API $B$N(B Fixup + $B%U%'!<%:$rDL$7$FZ%U%'!<%:$O$3$N%U%'!<%:$N(B$BA0(B$B$K9T$J$o$l$k$?$a!"(B + $B$=$3$G$OC1$K(B %{REMOTE_USER} + $B$H$9$k$3$H$,$G$-$k$^$9!#(B
  8. + +
  9. $BFbIt$N(B($B%U%!%$%kL>%Y!<%9$N(B) + $B%5%V%j%/%(%9%H$r$BJQ?t(B$B$N:G=*CM$r7hDj$9$kFCJL$J=q<0(B + %{LA-F:$BJQ?t(B} $B$,$"$j$^$9!#(B + $B$[$H$s$I$N>l9g$3$l$OA0=R$N(B LA-U $B$HF1$8$G$9!#(B
  10. +
+ +

CondPattern $B$O!">r7o%Q%?!<%s$G!"(B + $B8=:_$N(B TestString $B$NTestString $B$OI>2A$5$l$?8e$K(B CondPattern$B$KBP$7$F(B + $B%^%C%A%s%0$,9T$J$o$l$^$9!#(B

+ +

$BHw9M(B: CondPattern$B$O!"(B + $BI8=`$N(B$B3HD%@55,I=8=(B$B$K$$$/$D$+DI2C$r9T$C$?$b$N$G$9(B:

+ +
    +
  1. '!' $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$B$7$J$$(B$B%Q%?!<%s$r;XDj$G$-$^$9!#(B
  2. + +
  3. + CondPattern $B$N$A$g$C$H$7$?JQ +
  4. '<CondPattern' + ($B;z6g$NJB$SE*$K!"$h$j>.$5$$(B)
    + CondPattern $B$rC1$J$kJ8;zNs$H$7$F07$$!"(B + $B;z6g$NJB$S$H$7$F(B TestString $B$HHf3S$7$^$9!#(B + TestString $B$,;z6g$NJB$S$H$7$F(B + CondPattern $B$h$j>.$5$$>l9g$K??$K$J$j$^$9!#(B
  5. + +
  6. '>CondPattern' + ($B;z6g$NJB$SE*$K!"$h$jBg$-$$(B)
    + CondPattern $B$rC1$J$kJ8;zNs$H$7$F07$$!"(B + $B;z6g$NJB$S$H$7$F(B TestString $B$HHf3S$7$^$9!#(B + TestString $B$,;z6g$NJB$S$H$7$F(B + CondPattern $B$h$jBg$-$$>l9g$K??$K$J$j$^$9!#(B
  7. + +
  8. '=CondPattern' + ($B;z6g$NJB$SE*$KEy$7$$(B)
    + CondPattern $B$rC1$J$kJ8;zNs$H$7$F07$$!"(B + $B;z6g$NJB$S$H$7$F(B TestString $B$HHf3S$7$^$9!#(B + TestString $B$,;z6g$NJB$S$H$7$F(B + CondPattern $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 CondPattern $B$,C1$J$k(B"" + ($BFs$D$N0zMQId(B)$B$G$"$l$P!"(B + TestString $B$O6uJ8;zNs$HHf3S$5$l$^$9!#(B
  9. + +
  10. '-d' ($B%G%#%l%/%H%j(B (directory))
    + TestString $B$r%Q%9L>$H$7$F07$$!"$=$l$,B8:_$7$F!"(B + $B$+$D%G%#%l%/%H%j$G$"$l$P??!#(B
  11. + +
  12. '-f' ($BDL>o$N%U%!%$%k(B (file))
    + TestString $B$r%Q%9L>$H$7$F07$$!"$=$l$,B8:_$7$F!"(B + $B$+$DDL>o$N%U%!%$%k$G$"$l$P??!#(B
  13. + +
  14. '-s' ($BBg$-$5(B (size) + $B$N$"$kDL>o$N%U%!%$%k(B)
    + TestString $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
  15. + +
  16. '-l' ($B%7%s%\%j%C%/%j%s%/(B + (symbolic link))
    + TestString $B$r%Q%9L>$H$7$F07$$!"$=$l$,B8:_$7$F!"(B + $B$+$D%7%s%\%j%C%/%j%s%/$G$"$l$P??!#(B
  17. + +
  18. '-F' ($B%5%V%j%/%(%9%H$rDL$7$?4{B8%U%!%$%k(B) +
    + TestString $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!
  19. + +
  20. '-U' ($B%5%V%j%/%(%9%H$rDL$7$?4{B8(B URL) +
    + TestString $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!
  21. + + + + + + +
    $BCm0U(B: $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
    + +
+ +

$B$5$i$K!"(BRewriteCond + $B%G%#%l%/%F%#%V$X$NBh;00z?t$H$7$F(B CondPattern $B$KFCJL$J(B

+ +
+ [$B%U%i%0(B] +
+ $B$rDI2C$9$k$3$H$,$G$-$^$9(B + $B%U%i%0(B$B$O0J2<$N$b$N$r%+%s%^6h@Z$j$GJB$Y$?$b$N$G$9(B: + +
    +
  • 'nocase|NC' + (no case)
    + $B$3$l$OBgJ8;z>.J8;z$r6hJL$;$:$K%F%9%H$7$^$9!#(B$B$9$J$o$A!"(B + $BE83+$5$l$?(BTestString $B$H(B CondPattern $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(BTestString $B$H(B CondPattern $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
  • + +
  • + 'ornext|OR' + (or next condition)
    + $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 + +
    +
    +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
    +
    +
    + $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 +
  • +
+ +

$B;HMQNc(B:

+ +
+ $B%j%/%(%9%H$NCf$N(B ``User-Agent:'' $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 + +
+
+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]
+
+
+ $B2r>h$C$F$$$k(B) + $B%M%C%H%9%1!<%W%J%S%2!<%?$r;H$&>l9g!"%U%l!<%`(B$B$J$I(B$B$r4^$`(B + max $B$N%[!<%`%Z!<%8$r8+$k$3$H$K$J$j$^$9!#(B($BCl9g$O!"2hA|$d%F!<%V%k(B$B$J$I(B$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 +
+
+ +

RewriteRule

+ $B=q<0(B: RewriteRule + Pattern Substitution
+ $B%G%U%)%k%H(B: $B$J$7(B
+ $B%3%s%F%-%9%H(B: $B%5!<%P@_Dj%U%!%$%k!"(B + $B%P!<%A%c%k%[%9%H!"%G%#%l%/%H%j!"(B.htaccess
+ $B%*!<%P!<%i%$%I(B: + FileInfo
+ $B%9%F!<%?%9(B: Extension
+ $B%b%8%e!<%k(B: mod_rewrite.c
+ $B8_49@-(B: Apache 1.2 + (partially), Apache 1.3
+ +

RewriteRule + $B%G%#%l%/%F%#%V$O!"$BDj5A$9$k=g=x(B$B$O=EMW$G$9!#(B + $B$J$<$J$i!" + +

Pattern $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)$B@55,I=8=(B$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

+ +

$B@55,I=8=$NJ8K!$K4X$9$k%R%s%H(B:

+ + + + + +
+
+$B%F%-%9%H(B: 
+  .           $BG$0U$N0lJ8;z(B
+  [chars]     $BJ8;z%/%i%9(B: $B$$$:$l$+$NJ8;z(B
+  [^chars]    $BJ8;z%/%i%9(B: $B$3$l$i0J30$NJ8;z(B
+  text1|text2 $BA*Br;h(B: text1 $B$^$?$O(B text2
+
+$BJ8;z?t;XDj(B:
+  ?           $BD>A0$NJ8;z$N(B 0 $B2s$^$?$O(B 1 $B2s$N7+$jJV$7(B
+  *           $BD>A0$NJ8;z$N(B 0 $B2s0J>e$N7+$jJV$7(B
+  +           $BD>A0$NJ8;z$N(B 1 $B2s0J>e$N7+$jJV$7(B
+
+$B%0%k!<%T%s%0(B:
+  (text)      $B%F%-%9%H$N%0%k!<%T%s%0(B
+              ($BA*Br;h$N6-3&$rL@<($9$k!"H$r:n@.$9$k$?$a$K;H$&!#(B
+               N$BHVL\$N%0%k!<%W$O!"(BRewriteRule $B$N1&B&$NI=8=$G(B$N$B$H$7$F;2>H$9$k$3$H$,2DG=!#!K(B
+
+$BJ8;z0LCV$N;XDj(B:
+  ^           $B9TF,(B
+  $           $B9TKv(B
+
+$B%(%9%1!<%W(B:
+  \char       $BFCC$9(B)$B$9$k(B
+              ($BNc$($P(B ".[]()" $B$J$I(B)
+
+
+ +

$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(Bsrc/regex/regex.3 + $B$r;2>H$7$F$/$@$5$$!#$b$7@55,I=8=$d$=$NJQ$B$J$I(B)$B$K6=L#$,$"$l$P!"0J2<$N@lLg=q$r$4Mw2<$5$$(B:

+ +
+ Mastering Regular Expressions
+ Jeffrey E.F. Friedl
+ Nutshell Handbook Series
+ O'Reilly & Associates, Inc. 1997
+ ISBN 1-56592-257-3
+
+ +

($BLuCm(B: $BBh(B2$BHG$NF|K\8lHG(B)

+ +
+ $B>\@b(B $B@55,I=8=(B $BBh(B2$BHG(B
+ Jeffrey E. F. Friedl $BCx(B
+ $BEDOB(B $B>!(B $BLu(B
+ $B%*%i%$%j! + ISBN 4-87311-130-7
+
+ +

$B$5$i$K!"(Bmod_rewrite $B$G$O%Q%?!<%s$NA0$K(B NOT $BJ8;z(B('!') + $B$,;H$($^$9!#$3$l$G8eB3$N%Q%?!<%s$rH]Dj$9$k$3$H$,$G$-$^$9!#(B + $BNc$($F$$$&$J$i$P!"(B``$B$b$78=:_$N(B URL + $B$,$3$N%Q%?!<%s$K%^%C%A(B$B$7$J$1$l$P(B'' + $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

+ + + + + +
$BCm0U(B: 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 + $N $B$O;H$($^$;$s(B!
+ +

$B=q$-49$(%k!<%k$N(B Substitution $B$O!"(BPattern$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

+ +
    +
  1. RewriteRule $B%Q%?!<%s$X$N8eJ};2>H(B $N
  2. + +
  3. $B:G8e$K%^%C%A$7$?(B RewriteCond $B%Q%?!<%s$X$N8eJ};2>H(B + %N
  4. + +
  5. $B%k!<%k>r7o$N%F%9%HJ8;zNs$HF1MM$N%5!<%PJQ?t(B + (%{$BJQ?tL>(B})
  6. + +
  7. $B%^%C%T%s%04X?t(B $B$N8F$S=P$7(B + (${mapname:key|default})
  8. +
+ $B8eJ};2>H$O(B $N(N=0..9) + $B<1JL;R$GI=$7$^$9!#$3$l$O!"%^%C%A$7$?(B Pattern $B$N%0%k!<%W$NCf$G!"(B + N $BHVL\$N$b$N$NFbMF$KCV$-49$($i$l$^$9!#%5!<%PJQ?t$O(B + RewriteCond $B%G%#%l%/%F%#%V$N(B TestString $B$HF1$8$G$9!#(B + $B%^%C%T%s%04X?t$O(B RewriteMap $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 + +

$BA0=R$N$h$&$K!"$9$Y$F$N=q$-49$(%k!<%k$,(B Substitution $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 Substitution $B$K$h$C$F(B$B40A4$KCV$-49$($i$l(B$B!"(B + $B=q$-49$(=hM}$O(B L $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

+ +

'-' $B$H8F$P$l$kFC$BCV496X;_(B! $B$N0UL#$G$9!#JQ$G$7$g(B? + $B$$$$$(!"$3$l$O(B URL $B$N%^%C%A%s%0(B$B$@$1(B$B$r9T$J$$!"(B + $BCV49$r9T$J$o$J$$$H$$$&5!G=$rDs6!$7$F$/$l$k$b$N$G$9!#(B + $B$9$J$o$A(B$B!"(BC (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

+ +

$B$b$&$R$H$DCm0U;v9`(B: $B%/%(%j!C5n$7$?$$>l9g$O!"(B + $BCV49J8;zNs$r%/%(%9%A%g%s%^!<%/$@$1$G=*$o$i$;$k$h$&$K$7$^$9!#(B

+ + + + + +
$BCm0U(B: $BFChttp://thishost[:thisport] + $B$rCV$/$H!"(Bmod_rewrite + $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 +
+ + + + + +
$BHw9M(B: $B$3$N5!G=$N1F6A$G!"(B + http://thishost $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!"(BR + $B%U%i%0$r;H$&I,MW$,$"$j$^$9(B($B8e=R(B)$B!#(B
+ +

RewriteRule $B%G%#%l%/%F%#%V$NBh;00z?t$H$7$F!"(B + Pattern $B$KBP$7$F>e5-0J30$K$b0J2<$N$h$&$J(B

+ +
+ [$B%U%i%0(B] +
+ $B$r$D$1$k$3$H$,$G$-$^$9!#(B + $B%U%i%0(B$B$O0J2<$N$b$N$r%+%s%^$G6h@Z$C$F;XDj$7$^$9(B: + +
    +
  • + 'redirect|R + [=code]' ($B6/@)(B redirect)
    + + Substitution $B$NA0$K(B ($B?7$7$$(B URL $B$r(B URI $B$K$9$k(B) + http://thishost[:thisport]/ + $B$r$D$1$k$3$H$K$h$j6/@)E*$J30It%j%@%$%l%/%7%g%s$r9T$J$$$^$9!#(B + code $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 temp + ($B%G%U%)%k%H(B), permanent, seeother + $B$N$$$:$l$+$r;H$$$^$9!#(B$BNc$($P(B$B!"(B``/~'' + $B$r(B ``/u/'' $B$KJQ49$7$?$j!">o$K(B /u/ + user $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
    + +

    $BCm0U(B: + $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 + http://thishost[:thisport]/ + $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

    +
  • + +
  • 'forbidden|F' (URL $B$r6/@)E*$K(B + forbidden($B6X;_(B)$B$K$9$k(B)
    + $B$3$l$O8=:_$N(B URL $B$r6/@)E*$K%"%/%;%96X;_$K$7$^$9!#(B + $B$9$J$o$A(B$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
  • + +
  • 'gone|G' (URL $B$r6/@)E*$K(B + gone($B>C5n:Q$_(B)$B$K$9$k(B)
    + $B$3$l$O8=:_$N(B URL $B$r6/@)E*$K>C5n:Q$_(B(gone)$B$K$7$^$9!#(B + $B$9$J$o$A(B$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
  • + +
  • + 'proxy|P' ($B6/@)(B + proxy)
    + $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($B$9$J$o$A(B$B!"(B + $B$3$3$G=q$-49$(%k!<%k$rDd;_$7$F(B)$B%W%m%-%7%b%8%e!<%k$r(B$BDL$7$F=PNO$7$^$9!#(B + $BCV49BP>]J8;zNs$O(B($BNc$($P(B$B!"IaDL$O(B http:// + hostname$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 ProxyPass + $B%G%#%l%/%F%#%V$NA06u4V$K%^%C%W$9$k$3$H$,$G$-$^$9!#(B + +

    $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``httpd + -l'' $B$N=PNO$NCf$K(B mod_proxy.c + $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 ``httpd'' + $B%W%m%0%i%`$r:F9=C[$9$kI,MW$,$"$j$^$9!#(B

    +
  • + +
  • 'last|L' + (last($B:G8e$N(B)$B%k!<%k(B)
    + $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 last $B%3%^%s%I$d(B C $B8@8l$N(B break + $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 ('/') + $B$r$BNc$($P(B '/e/www/' + $B$K=q$-49$($^$9!#(B
  • + +
  • 'next|N' + (next($B + $B=q$-49$(=hM}$r(B($B0lHV:G=i$N=q$-49$(%k!<%k$+$i(B)$B:Fnext $B%3%^%s%I$d(B C $B8@8l$N(B continue + $B%3%^%s%I$KBP1~$9$k$b$N$G$9!#(B + $B=q$-49$(=hM}$r:F5/F0$7$?$$$H$-(B + $B$9$J$o$A!"(B$B%k!<%W$N@hF,$KLa$j$?$$$H$-(B
    $B$K(B + $B$3$N%3%^%s%I$r;H$C$F$/$@$5$$!#(B + $B$?$@$7!"L58B%k!<%W$r:n$i$J$$$h$&$KN10U$7$F$/$@$5$$(B! +
  • + +
  • 'chain|C' + ($Bchained ($B%A%'%$%s(B))
    + $B$3$N%U%i%0$r;XDj$9$k$H!"8=:_$N%k!<%k$Oo$I$*$j9T$o$l$^$9!#(B + $B$9$J$o$A(B$B%U%i%0$O2?$N1F6A$bM?$($^$;$s!#%k!<%k$,%^%C%A(B + $B$7$J$$(B$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 ``.www'' + $B$NItJ,$r + +
  • + 'type|T=MIME-type' + (MIME type $B$N6/@);XDj(B)
    + $B%?!<%2%C%H%U%!%$%k$N(B MIME $B%?%$%W$r6/@)E*$K(B MIME-type + $B$K$7$^$9!#Nc$($P$3$l$r;H$C$F!"(Bmod_alias + $B$N%G%#%l%/%F%#%V$G$"$k(B ScriptAlias + $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``application/x-httpd-cgi'' + $B$K6/@)%;%C%H$9$k$b$N$G$9!#(B
  • + +
  • + 'nosubreq|NS' (no + sub-request, + $BFbIt$N(B + $B%5%V%j%/%(%9%H$,$J$$(B + $B$H$-$N$_;H$o$l$k(B)
    + $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!"(Bmod_include + $B$,%G%#%l%/%H%j$N%G%U%)%k%H$N8uJd$H$J$k%U%!%$%k$N>pJs(B + (index.xxx) $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
    + +

    $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

    +
  • + +
  • 'nocase|NC' + (no case)
    + $B$3$l$O(B$B%Q%?!<%s(B$B$K$D$$$FBgJ8;z>.J8;z$r6hJL$7$J$$$h$&$K$7$^$9!#(B + $B$9$J$o$A(B$B!"(B$B%Q%?!<%s(B$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
  • + +
  • 'qsappend|QSA' + (query string + append)
    + $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!l9g$K$3$N%U%i%0$r;H$$$^$9!#(B
  • + +
  • + 'noescape|NE' + (no URI escaping of + output)
    + $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 + RewriteRule /foo/(.*) /bar?arg=P1\%3d$1 [R,NE] + + + $B$3$NNc$G$O!"(B'/foo/zed' $B$,0BA4$J%j%/%(%9%H$G$"$k(B + '/bar?arg=P1=zed' $B$KJQ99$5$l$^$9!#(B + + + + + +
    $BCm0U(B: + noescape $B%U%i%0$O(B Apache 1.3.20 + $B0J9_$G$N$_M-8z$G$9!#(B
    +
  • + +
  • + 'passthrough|PT' + (pass through to next + handler)
    + $B$3$N%U%i%0$O!"FbIt$N(B request_rec $B9=B$BN$N(B + uri $B%U%#!<%k%I$K(B filename + $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!"(BRewriteRule + $B%G%#%l%/%F%#%V$N=PNO$KBP$7$F!"B>$N(B URI + $B$+$i%U%!%$%kL>$X$NJQ49=hM}$r9T$&(B Alias, + ScriptAlias, Redirect + $B$H$$$C$?(B$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: mod_rewrite + $B$N=q$-49$(%(%s%8%s$G(B /abc $B$+$i(B /def + $B$X$NJQ49$r9T$J$$!"$5$i$K(B mod_alias $B$G(B + /def $B$+$i(B /ghi + $B$K=q$-49$($k$K$O!"0J2<$N$h$&$K$7$^$9(B: +
    +    RewriteRule ^/abc(.*)  /def$1 [PT]
    +    Alias       /def       /ghi
    +   
    +
    + $B$b$7(B PT $B%U%i%0$r;XDj$9$k$N$rK:$l$F$7$^$C$?>l9g!"(B + mod_rewrite $B$O$A$c$s$H$=$N;E;v$r9T$J$$$^$9!#(B + $B$9$J$o$A(B$B!"40A4$J(B API $B$K=`5r$7$?(B URI-to-filename + $BJQ49%k!<%A%s$,9T$&$Y$-!"(Buri=/abc/... $B$r(B + filename=/def/... $B$K=q$-49$(!"$r9T$J$$$^$9!#$=$N8e(B + mod_alias $B$,5/F0$5$l!"(BURI-to-filename + $BJQ49$r;n$_$^$9$,!"$3$l$OF0:n$7$^$;$s(B $B!#(B + +

    $BCm0U(B: 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$BE57?E*$JNc$H$7$F$O!"(B + mod_alias $B$H(B mod_rewrite + $B$NF1;~;HMQ$G$9!#(B

    + + + + +
    $BCm0U(B - Apache $B%O%C%+!<$X(B: +
    + $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
    +
  • + +
  • 'skip|S=num' + (skip next rule(s))
    + $B$3$N%U%i%0$O=q$-49$(%(%s%8%s$KBP$7!"8=:_$N%k!<%k$,%^%C%A$7$?$i!"(B + $Bnum $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 skip=N $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 + $B0[$J$j$^$9(B!)$B!#(B
  • + +
  • + 'env|E=VAR:VAL' + (set environment variable)
    + $B$3$l$O(B VAR $B$H$$$&L>A0$N4D6-JQ?t$NCM$r(B VAL + $B$K$9$k$h$&;X<($7$^$9!#$3$3$G(B VAL + $B$K$O!"@55,I=8=$N8eJ};2>H$H$7$FE83+$5$l$k(B $N $B$H(B + %N $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 (<!--#echo + var="VAR"--> $B$rDL$7$F(B) $B$^$?$O(B CGI ($BNc$($P(B + $ENV{'VAR'}) $B$N$h$&$K!";2>H$5$l$^$9!#$5$i$K!"(B + RewriteCond $B%Q%?!<%s(B %{ENV:VAR} + $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 +
+ + + + + +
+ $BCm0U(B: + $B%5!<%PC10L$N@_Dj%U%!%$%k$NCf$G$O!"(BPattern $B$O40A4$J(B + URL $B$KE,MQ$5$l$k$3$H$rK:$l$J$$$G$/$@$5$$!#(B + $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 + $B$B!"CV49$,=*$o$C$?8e$K<+F0E*$K(B$BIU2C(B + $B$5$l$^$9!#(B$B$3$N5!9=$O!"$5$^$6$^$Jo$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 + +

$B$R$H$DNc30$,$"$j$^$9(B: $BCV49J8;zNs$,(B ``http://'' + $B$G;O$^$C$F$$$k>l9g!"%G%#%l%/%H%j@\F,<-$OIU2C(B$B$5$l$:(B + $B!"30It%j%@%$%l%/%H$^$?$O(B (P $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

+
+ + + + + +
$BCm0U(B: $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 + ``RewriteEngine On'' $B$r%;%C%H$7!"(B$B$+$D(B + ``Options FollowSymLinks'' $B$rM-8z$K(B + $B$7$J$1$l$P$J$j$^$;$s!#$"$J$?$N$H$3$m$N4IM}FollowSymLinks $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
+ +

$B0J2<$KM-8z$JCV49$NAH9g$;$H!"$=$l$i$N0UL#$r<($7$^$9(B:

+ +

$B%j%/%(%9%H(B ``GET /somepath/pathinfo'' + $B$,9T$J$o$l$?>l9g$N!"(B
+ $B%5!<%PC10L$N@_Dj(B (httpd.conf) $B$NFbIt(B:

+

+ + + + + +
+
+$BM?$($i$l$?%k!<%k(B                                      $BCV497k2L(B
+----------------------------------------------  ----------------------------------
+^/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
+
+
+ +

$B%j%/%(%9%H(B ``GET /somepath/localpath/pathinfo'' + $B$,9T$J$o$l$?>l9g$N!"(B
+ /somepath $B$K4X$9$k%G%#%l%/%H%jC10L$N@_Dj$NFbIt(B:
+ ($BNc$($P(B$B!"(B + /physical/path/to/somepath $B%G%#%l%/%H%j$K$"$C$F!"(B
+ RewriteBase /somepath $B$N5-=R$,$"$k(B + .htaccess $B%U%!%$%k(B):

+

+ + + + + +
+
+$BM?$($i$l$?%k!<%k(B                                      $BCV497k2L(B
+----------------------------------------------  ----------------------------------
+^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
+
+
+ +

$BNc(B:

+ +
+ $B$3$3$G$O!"(B +
+ / Language /~ + Realname /.../ File +
+ + $B$H$$$&=q<0$N(B URL $B$r(B + +
+ /u/ Username /.../ + File . Language +
+ + $B$K=q$-49$($?$$$b$N$H$7$^$9!#(B + +

$BA0=R$N%^%C%W%U%!%$%k$r(B /path/to/file/map.txt + $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:

+ +
+
+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
+
+
+
+
+ +
+

$B$=$NB>$N>pJs(B

+
+
+ +

$B4D6-JQ?t(B

+ $B$3$N%b%8%e!<%k$O!"(BSCRIPT_URL $B$H(B + SCRIPT_URI $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$BO@M}E*$J(B + Web $B%S%e!<$,F~$C$F$$$^$9!#0lJ}!"I8=`$N(B CGI/SSI $BJQ?t$G$"$k(B + SCRIPT_NAME $B$H(B SCRIPT_FILENAME + $B$K$O!"(B$BJ*M}E*$J(B$B%7%9%F%`%S%e!<$,F~$C$F$$$^$9!#(B + +

$BCm0U(B: $B$3$l$i$NJQ?t$NCf$K$O!"(B$B:G=i$K%j%/%(%9%H$r + $B$9$J$o$A(B$B!"=q$-49$($,9T$o$l$k(B$BA0$N(B 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

+ +

$BNc(B:

+ +
+
+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/
+
+
+
+ +

$B

+ $B$3$NJ8=q0J30$K$b!"(BURL + Rewriting Guide $B$H$$$&J8=q$,$"$j$^$9!#$3$NCf$K$O!"(BURL + $B%Y!<%9$NLdBj$K$D$$$F!"pJs$r8+$k$3$H$,$G$-$k$G$7$g$&!#(B +
+
+ +

Apache HTTP Server Version 1.3

+ Index + Home + + + + + -- cgit v1.2.3