Let me keep this short: I'm trying to do something fairly simple with mod_rewrite on Apache 1.3.x, and mod_rewrite isn't cooperating. As a matter of fact, mod_rewrite isn't doing ANYTHING.
Consider the following sample directives:
RewriteEngine On
RewriteLog /tmp/apache-rewrites
RewriteLogLevel 9
RewriteCond %{REQUEST_URI} .*babcom.* [NC]
RewriteRule ^/(.+) http://www.caerllewys.net/$1 [R]
It should be apparent that this test rule should simply munge any URL containing the string 'babcom' and redirect it to caerllewys.net. (I don't care at this point whether the resulting URL is valid, I just want it to do SOMETHING.)
So, we turn the rewrite engine on. We tell mod_rewrite to log to /tmp/apache-rewrites at log level 9, and it obligingly opens the log file.
And that's the last thing it ever does. mod_info says the module is loaded and has parsed its rules. But it's not doing ANYTHING. It never rewrites, and it never logs a thing.
Have any of you geekly types ever run into this behavior before? Am I missing something stupidly, blindingly obvious? Is there some secret, undocumented restriction against using both mod_rewrite and mod_alias? Does Apache just hate me?
Update:
Problem is solved. The Apache documentation never mentions that if you're running vhosts, mod_rewrite directives need to go in the vhost sections, not in the global section.
no subject
2. is the logfile suitably permissioned?
3. if you drop the RewriteCond and just have the above in the relevant vhost, what happens?
The above also would NOT redirect this URL:
"http://www.babcom.com/" because it does not match the regex in RewriteRule. (The .+ fails it).
no subject
(I'm assuming I still only turn RewriteEngine On once, in the global section.)
no subject
no subject
I haven't seen it specifically highlighted anywhere, but it is documented.
RewriteEngine Directive (http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriteengine)
"Note that, by default, rewrite configurations are not inherited. This means that you need to have a RewriteEngine on directive for each virtual host in which you wish to use it."
no subject
no subject
OOOOOOOOOOOOOOoooooooooooooohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.
Dammit.
So that's the problem.
(grumble grumble)
no subject
no subject
Spent 2 days trying to figure out WTF it wasn't working - worked in the examples I had.
Gave up said "*@&$(*@$@#*(#@ Apache" and came up with a workaround on the filesystem.
Asked our "Web Guy" who does Apache for his job description about it, he said "I dunno, man, looks good to me."
no subject
RewriteCond %{REQUEST_URI} /BADUSER/.*\.mp3$ [NC]
RewriteRule .* - [L,F]
and make it block by MIME type instead of file extension. Theoretically I should be able to do it using %{HTTP:Content-Type}. Then I can block video/* and audio/* regardless of file extension.