2010-07-20

Replacing Images With mod_rewrite

OpenGroupware Legacy's WebUI has an extensive themeing system... but sometimes you just want to replace a couple images. Doing so is possible using Apache's mod_write module; and you don't have to touch any of the files installed by the OpenGroupware packages. The key to using mod_rewrite to 'overload' image references is that mod_rewrite supports the chaining of conditions [via RewriteCond] so rewriting rules can only apply to certain requests.

Adding:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} \.(jpg|jpeg|gif|png)$
RewriteCond /srv/www/htdocs/override/%{REQUEST_FILENAME} -f
RewriteRule ^(.+) /override/$1 [L]
</IfModule>
<Directory /srv/www/htdocs/override>
Order allow,deny
Allow from all
</Directory>

- to the vhost entry of your OpenGroupware Legacy instance allows you to overload any reference to a request ending in jpg, jpeg, gif or png. But this only happens if a file of the same name exists in our overload directory. So if you don't create an eponymously named file then nothing changes,

So a request for -
https://tor.example.com/OpenGroupware11.woa/WebServerResources/English.lproj/homepage2.gif
- gets rewritten to -
https://tor.example.com/override/OpenGroupware11.woa/WebServerResources/English.lproj/homepage2.gif
- if and only if a file with a path and name of -
/srv/www/htdocs/override/OpenGroupware11.woa/WebServerResources/English.lproj/homepage2.gif
- exists. Otherwise the file is delivered from the usual place via the Alias directive in your ogo-webui.conf file included into your Apache configuration:
Alias /OpenGroupware11.woa/WebServerResources/ /usr/local/share/opengroupware.org-1.1/www/
<Directory local="" opengroupware.org-1.1="" share="" usr="" www="">
Order allow,deny
Allow from all </directory>

No comments:

Post a Comment