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/12/31 04:16:42 UTC

[Httpd Wiki] Update of "RewriteMisc" by RichBowen

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 RichBowen:
http://wiki.apache.org/httpd/RewriteMisc

The comment on the change is:
Probably want to call this something more meaningful than simply miscellaneous

New page:
== Look somewhere else for that image ==

If the image isn't in the /images/ directory, look in /images1/, /images2/, and /images3/ for it as well.

{{{
RewriteEngine On

# RewriteLog /tmp/rewrite.log
# RewriteLogLevel 6

RewriteRule ^/images/(.*) $1
RewriteCond /usr/local/apache/htdocs/images/%{REQUEST_FILENAME} -f
RewriteRule ^ /usr/local/apache/htdocs/images/%{REQUEST_FILENAME} [L]

RewriteCond /usr/local/apache/htdocs/images1/%{REQUEST_FILENAME} -f
RewriteRule ^ /usr/local/apache/htdocs/images1/%{REQUEST_FILENAME} [L]

RewriteCond /usr/local/apache/htdocs/images2/%{REQUEST_FILENAME} -f
RewriteRule ^ /usr/local/apache/htdocs/images2/%{REQUEST_FILENAME} [L]

RewriteCond /usr/local/apache/htdocs/images3/%{REQUEST_FILENAME} -f
RewriteRule ^ /usr/local/apache/htdocs/images3/%{REQUEST_FILENAME} [L]
}}}

== Redirect Everything ==

I want all requests to my site to get sent to a certain page. Perhaps for a "system is down for maintenance" condition, or perhaps there's really only one page here. So, for example, let's send everything to '''page.html'''

{{{
RewriteEngine On
RewriteRule !^/page\.html$ /page.html [PT]
}}}

Or, if you want all pages mapped to a handler that knows what to do with that page:

{{{
RewriteEngine On
RewriteCond $1 !=/handler.php
RewriteRule ^(.*) /handler.php?uri=$1 [PT]
}}}


= Connecting to Tomcat =
== Problem: ==
We are using the 2.2 branch of Apache HTTP Server as frontend while all requests with a jsp extension should be served by our tomcat backend server on Port 8009.

== Recipe: ==
{{{
RewriteEngine On
RewriteRule ^/(.+\.jsp)$ ajp://localhost:8009/$1 [P]

ProxyPassReverse / ajp://localhost:8009/
}}}

== Discussion: ==
Mod_rewrite passes all requests which are ending with .jsp to mod_proxy (["Flags/P"]). We use the Apache JServ Protocol (ajp), this means the modules [http://httpd.apache.org/docs/trunk/mod/mod_proxy_ajp.html mod_proxy_ajp] and mod_proxy must be loaded into the server configuration.

= Load balancing =
== Problem: ==
We have one frontend server which serves static content while the processing of dynamical content is up to two backend servers.

== Recipe: ==
Using mod_rewrite, mod_proxy and mod_proxy_balancer.
{{{
RewriteEngine On
RewriteRule ^/(.+\.php)$ balancer://myphpcluster/$1 [P]

<Proxy balancer://myphpcluster>
    BalancerMember http://10.0.0.1 smax=10 loadfactor=20
    BalancerMember http://10.0.0.2 
    ProxySet maxattempts=2
</Proxy>

ProxyPassReverse / http://10.0.0.1/
ProxyPassReverse / http://10.0.0.2/
}}}

== Discussion: ==
''A brief description may be provided in the future.''

For a list of available ProxyPass parameters see the [http://httpd.apache.org/docs/trunk/mod/mod_proxy.html#proxypass mod_proxy documentation].

'''Note:''' The directive ProxySet is undocumented. You can use this directive in order to set additional parameters for a balancer or a worker, because the following does not work as expected:
{{{
# maxattempts=2 and other paramters are not recognized this way
RewriteRule ^/(.+\.php)$ balancer://myphpcluster/$1 [P] maxattempts=2
}}}