[ale] Next apache puzzle: RewriteCond on auth failure
Chris Woodfield
rekoil at semihuman.com
Fri Sep 19 15:54:44 EDT 2008
Thanks for the response on my last question, I got that problem licked
- the answer was to use <LocationMatch> instead of <FileMatch>, since
the path did not actually link to an actual file, but a string being
fed to the php script.
Next up, I'm attempting to configure apache to issue redirect requests
for all "heavy" objects on my server in the /gallery/ directory to
point to a CDN - requests for HTML will still hit the server, but
requests for .jpg, .gif, etc should receive a 301 redirect to a
different hostname, which is configured with the proper auth
credentials to access the content from apache.
Below is my best guess on how to make it work, but so far no dice:
<LocationMatch "/gallery/.*\.(gif|jpg|jpeg|png)$">
Header set Cache-control "max-age=86400, stale-if-error=3600"
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond !%{HTTP_AUTH} .*
RewriteRule ^(.*)$ http://wwwcache.semihuman.com/$1 [R=301,L]
</IfModule>
</LocationMatch>
<Directory "/usr/share/gallery2/">
AuthUserFile /usr/share/gallery2/.htpasswd
AuthGroupFile /dev/null
AuthName ByPassword
AuthType Basic
...
</Directory>
I've confirmed the RewriteRule issues the proper redirect if I comment
out the RewriteCond line - the tough part is crafting a RewriteCond
that will only be triggered if HTTP authentication fails.
Again, any advice?
-C
More information about the Ale
mailing list