Apache URL rewriting in reverse proxy
This is how I got it to work. As well as the changes as per my comment to my original question, I needed to exclude .js
and .css
from the rule that added a trailing slash.
<VirtualHost *:80>
ServerAdmin admin@localhost
ServerName mydomain.com
ServerAlias www.mydomain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteLog ${APACHE_LOG_DIR}/rewrite.log
RewriteLogLevel 9
Alias /images/ "/var/www/images/"
RewriteEngine On
# rewrite rule to prevent proxy exploit
RewriteCond %{REQUEST_URI} !^$
RewriteCond %{REQUEST_URI} !^/
RewriteRule .* - [R=400,L]
# consolidate non-www requests onto the www subdomain
RewriteCond %{HTTP_HOST} ^yourdomain\.com$
RewriteRule ^(.*) http://www.yourdomain.com/$1 [R=301,L]
# Add a trailing slash to the URL (ignoring images, CSS and JavaScript)
RewriteCond %{REQUEST_URI} !^/(images)(.*)$
RewriteCond %{REQUEST_URI} !^/(.*)(.js|.css)$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}$1/ [R=301,L]
# proxy to the Jellyfish server (ignoring images)
RewriteCond %{REQUEST_URI} !^/(images)(.*)$
RewriteRule ^(/.*)$ http://app-server:8181/jellyfish$1 [P]
ProxyPassReverse / http://app-server:8181/jellyfish/
# suppress mod_security rules that were giving false positives
SecRuleRemoveById 981059 981060
<Directory "/var/www/images">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>