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).
A bit of discussion about your current rules...
I've tried to add this on line 4; RewriteCond %{REQUEST_URI} !^ inc/tools/ [NC]
This gave RewriteCond: bad argument line error
Because you have an erroneous space in the middle of the CondPattern !^ inc/tools/
. However, that expression still won't give the correct result (see below).
I've tried to add this to line 2;
RewriteCond %{REQUEST_URI} ^/inc/tools/(.*)$
RewriteRule ^.*$ - [L]
You are close with this. However, the REQUEST_URI
server variable contains the full URL-path, not the URL-path relative to where the .htaccess
file is located. So, this would need to be of the form:
RewriteCond %{REQUEST_URI} ^/sdf19/inc/tools/
RewriteRule ^ - [L]
This would need to go near the top of your .htaccess
file, immediately after the RewriteEngine On
directive. The (.*)$
at the end of the CondPattern was superfluous, as was the RewriteRule
pattern ^.*$
. However, this can be written more efficiently as a single directive and testing with the RewriteRule
pattern instead. You can then omit the /sdf19
subdirectory. For example:
RewriteRule ^inc/tools/ - [L]
I've tried adding a .htaccess
in /inc/tool
s with RewriteEngine OFF
, didn't work.
Well, that should have worked. (Unless perhaps you have mod_alias directives in the parent .htaccess
file that are conflicting?) So, it's unclear, given what you've stated in the question why it didn't. Do you have other directives in your .htaccess
file?
everything I have tried so far i get redirected to base http://url/sdf19/
That is also strange, because nothing you've shown so far would result in an external redirect. Do you have other directives in your .htaccess
file? A mod_alias Redirect
or RedirectMatch
directive perhaps?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)\/?$ index.php?page=$1 [NC]
RewriteRule ^([a-z]+)\/([0-9]+)\/?$ index.php?page=$1&id=$2 [NC]
RewriteRule ^([a-z]+)\/([a-z]+)\/?$ index.php?page=$1&action=$2 [NC]
RewriteRule ^([a-z]+)\/([a-z]+)\/([0-9]+)\/?$ index.php?page=$1&action=$2&id=$3 [NC]
A potential problem with these directives is that RewriteCond
directives only apply to the first RewriteRule
that follows. So, the 2nd, 3rd and 4th RewriteRule
directives above are being executed unconditionally and explains why requests to /sdf19/inc/tools
are being caught by the third rule.
You would either need to include those same conditions before every RewriteRule
(ie. the rule is only processed when the request does not map to a file and does not map to a directory). Or, negate their meaning and prevent further processing if a file or directory is requested - however, this can depend on whether you have more directives later in your file that still need to be processed under these conditions.
You are also missing L
flags on these directives, so processing is (unnecessarily?) continuing through your file.
So, try the following instead:
# Prevent further processing if a file or directory is requested
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Route other URLs
RewriteRule ^([a-z]+)\/?$ index.php?page=$1 [NC,L]
RewriteRule ^([a-z]+)\/([0-9]+)\/?$ index.php?page=$1&id=$2 [NC,L]
RewriteRule ^([a-z]+)\/([a-z]+)\/?$ index.php?page=$1&action=$2 [NC,L]
RewriteRule ^([a-z]+)\/([a-z]+)\/([0-9]+)\/?$ index.php?page=$1&action=$2&id=$3 [NC,L]
Best Answer
What does your Apache error log say? Your site loads without the
.htaccess
in place, correct?In my experience, when a 500 error is connected to
.htaccess
it could be something as simple as the.htaccess
file itself getting munged on the file system. I would recommend deleting the actual file and creating a new.htaccess
. If that still shows a 500 error, then go through the.htaccess
line by line commenting out each line and reload the page. Chances are there is something odd in at least one line and this will show it.EDIT: I Looked closer at your
.htaccess
content since you added it & think I spotted the issue. Change it to read like so:It seems like your formatting of the RewriteCond would choke. Also, I adjusted it to the way I would do it which reads in human form:
This way you are clearly grabbing anything and everything that is not
www.mywebsite.com
and sending them to the proper domain.Also, in your Apache config I would recommend a
ServerAlias
to account forwww.mywebsite.com
. It seems like you are usingNameVirtualHost
so having the main server name bewww.mywebsite.com
with an alias beingmywebsite.com
makes the most sense.