You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wiki-changes@httpd.apache.org by Apache Wiki <wi...@apache.org> on 2008/04/11 15:15:45 UTC

[Httpd Wiki] Update of "RewriteVirtualHandler" by noodl

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Httpd Wiki" for change notification.

The following page has been changed by noodl:
http://wiki.apache.org/httpd/RewriteVirtualHandler

The comment on the change is:
Rearrange for the most common use cases and simplify non-capturing matches

------------------------------------------------------------------------------
  
  The rules shown here are designed to work in !VirtualHost context. For information on translating them for .htaccess context, see RewriteContext
  
+ === Map all URIs except those corresponding to existing files to a handler ===
+ {{{
+ RewriteEngine On
+ RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
+ RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
+ RewriteRule . /script.php
+ }}}
+ 
+ This ruleset and the following will usually require the script to interpret the REQUEST_URI environment variable to determine what actions to take.
+ 
  === Map any request to a handler ===
  
- In the case where all URIs should be sent to the same place (including potentially requests for static content) the method to use depends on the type of the handler. For cgi scripts, use:
+ In the case where all URIs should be sent to the same place (including potentially requests for static content) the method to use depends on the type of the handler. For php scripts, use:
- 
- {{{
- ScriptAliasMatch .* /var/www/script.cgi
- }}}
  
  For other handlers such as php scripts, use:
  {{{
  RewriteEngine On
- RewriteCond %{REQUEST_URI} !script.php
- RewriteRule . /script.php
+ RewriteRule !^/script.php /script.php
  }}}
  
- The purpose of the {{{RewriteCond}}} here is to avoid [:RewriteLooping:looping].
+ And for CGI scripts:
+ {{{
+ ScriptAliasMatch .* /var/www/script.cgi
+ }}}
  
  === Map URIs corresponding to existing files to a handler instead ===
  
  {{{
  RewriteEngine On
- RewriteCond %{REQUEST_URI} !script.php
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
- RewriteRule . /script.php
+ RewriteRule !^/script.php /script.php
  }}}
  
  If the existing files you wish to have handled by your script have a common set of file extensions distinct from that of the hander, you can bypass {{{mod_rewrite}}} and use instead {{{mod_actions}}}. Let's say you want all .html and .tpl files to be dealt with by your script:
@@ -42, +49 @@

  AddHandler foo-action html tpl
  }}}
  
- === Map all URIs except those corresponding to existing files to a handler ===
- {{{
- RewriteEngine On
- RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
- RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
- RewriteRule . /script.php
- }}}
- 
- This ruleset will usually require the script to interpret the REQUEST_URI environment variable to determine what actions to take.
-