Probably the ProxyPass /
directive you have in your config routes all requests to the Tomcat backend, bypassing all your mod_rewrite directives. You can try to remove the ProxyPass
directive and use RewriteRule
with the [P]
flag after your other rewrites:
For the expire headers the situation is worse — in another similar question a solution was not found.
Option +FollowSymLinks
would be needed for using mod_rewrite in .htaccess
files; in your case it is not required, because you can put everything in the Apache config. Moving rules from config to .htaccess
is pointless and can only make things slower. However, there is an important difference between .htaccess
and the Apache config — in .htaccess
patterns in RewriteRule
are matched against relative filesystem paths (which never start with /
), while in the VirtualHost
context these patterns are matched against the URL path after the hostname, which always starts with /
. Therefore at least one of your rules is incorrect:
RewriteRule ^content/(js|css)/([a-z]+)-([0-9]+)\.(js|css)$ /content/$1/$2.$4
should be
RewriteRule ^/content/(js|css)/([a-z]+)-([0-9]+)\.(js|css)$ /content/$1/$2.$4
(note the additional slash in the beginning).
Your original rewrite rule likely confused things because the $1 pattern that matched already had a '/' in it, thus you created a double slash. What happens if you use:
RewriteRule ^(.*)$ http://www.domain.com$1 [QSA,L,R=301]
and remove your extra rule?
UPDATE 1
You have misinterpreted what I meant. I wasn't talking about your workaround, but the original rule.
To make it more obvious what you are doing wrong and which is potentially causing issues, use:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^/(.*)$ http://www.domain.com/$1 [L,R=301]
Note how I have explicitly listed the '/' outside of the sub pattern. Only by doing that would it be okay to use a '/' before '$1'. If you don't you will get repeating slashes.
I'd also suggest dropping QSA. Examples I see elsewhere on the Internet don't use that either.
Finally, you should escape the '.' in the host name being matched else could technically match stuff other than a literal '.' as well.
So, try that. If still issues, then you should enable rewrite module logging and see what is going on. You possibly have some other rewrite rules in your configuration which are causing issues.
UPDATE 2
Hmmm, finally realised your actual problem is that you have the rewrite rule inside of the Directory directive container instead of outside.
So, move the rewrite rules to immediately inside of the VirtualHost and not the Directory directive.
Best Answer
Firstly your rewrite rule has a small error. It should use a full URL for the redirect (cf. description of redirect flag):
However this doesn't explain why the rewrite rule is not triggered. As mentioned in the comment above, you must make sure that the
rewrite.config
file is in the write place. With the defaultserver.xml
configuration (engine nameCatalina
, host namelocalhost
) you need to put it in:$CATALINA_BASE/conf/Catalina/localhost
if you added theRewriteValve
to the<Host>
element of yourserver.xml
.WEB-INF
folder of your application, if you added theRewriteValve
to the<Context>
element of your application.In any case it might help you to increase the log level of the Servlet logger:
in
$CATALINA_BASE/conf/logging.properties
, which will log tolocalhost.<date>.log
the lines:whenever the
RewriteValve
is properly configured.