2

I am trying to get mod_rewrite rules to work under apache 2.2 on Debian Lenny. To try to get it to work first I put the rules in /etc/apache2/mods-enabled/rewrite.load:

RewriteEngine On
RewriteRule http-poll/ http://jabberserver:5280/http-poll [P]
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 3

However I get 404 error when I use a browser to go to http://localhost/http-poll after restarting apache. Error.log has:

[Wed Jun 30 15:22:53 2010] [error] [client 127.0.0.1] File does not exist: /var/www/http-poll

"/tmp/rewrite.log" is empty.

I have enabled modules( including mod_rewrite) (a2enmod rewrite proxy proxy_http)

4
  • I reckon this is not a SF question @David: "Please note that Server Fault is not for general computer troubleshooting questions; if you paid for that desktop hardware, and it's your personal workstation, it is unlikely that your question is appropriate for Server Fault."
    – Ivo Flipse
    Jun 30, 2010 at 18:17
  • 1
    With all due respect, how is a question about server configuration not appropriate for ServerFault? Nowhere in this question does it say it's about a personal workstation.
    – David Z
    Jun 30, 2010 at 23:47
  • The word server is also not mentioned anywhere explicit (other than jabberserver). SF is site for professional sys-admins and they like to keep it that way @David
    – Ivo Flipse
    Jul 1, 2010 at 6:09
  • 1
    Apache is a server. And the people who ask and answer questions about its configuration generally tend to be sysadmins.
    – David Z
    Jul 1, 2010 at 7:46

4 Answers 4

1

I notice that in your rewrite rule, the pattern to match ends with a slash, but the URL you accessed didn't. Try removing the slash from http-poll/ in the RewriteRule and see if that makes it work.

2
  • Same behaviour with: RewriteRule http-poll jabberserver:5280/http-poll [P] after apache2 restart. ie: [Wed Jun 30 18:34:05 2010] [error] [client 192.168.xx.xxx] File does not exist: /var/www/http-poll Thanks for the suggestion though.
    – user13146
    Jun 30, 2010 at 8:38
  • Odd. I'd suggest enabling the rewrite log and setting its level to something verbose, and see what shows up in the log. Usually when I have rewriting problems, the information there shows exactly what's going wrong.
    – David Z
    Jun 30, 2010 at 23:48
1

I think you need both to specify the absolute path, and ensure the pattern is at the beginning of the local path:

RewriteRule ^/http-poll/ http://jabberserver:5280/http-poll/ [P]

since otherwise the rewrite rule will apply again if the same Apache conf file interprets the proxy.

Additionally, if you want to redirect URLs under /http-poll/, you should specify regex substitutions:

RewriteRule ^/http-poll/(.*) http://jabberserver:5280/http-poll/$1 [P]

And, yes, this is definitely a Server Fault qn.

1
  • I tried that and it did not work. I am going to go with a ProxyPass/ProxyPassReverse solution instead. Thanks for the help though.
    – user13146
    Jul 2, 2010 at 8:00
1

None of the other answers have explained why your rewrite log is empty.

Here's my guess: unless you have included the directive "RewriteOptions Inherit", global rewrite directives will not be inherited by VirtualHost directives (which is inconsistent with how a lot of other Apache configuration works).

Besides turning on the inheritance option, you can repeat the related Rewrite directives in the virtualhost you are testing.

The suggestion elsewhere to check your "LoadModule" line is not related. If that were missing, your configuration most likely would be broken, and you would get an error like this instead:

"Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration"

The exception to that would be if you wrapped all your Rewrite directives in "IfModule" blocks, so that they simply disappeared when the module was missing.

0

Shouldn't mod_rewrite.load only contain a line like this?

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

Anyway, it works for me if I put the rewrite rules in a server configuration (<VirtualHost>), but not if they're in the mod_rewrite.load (Ubuntu 8.04, Apache 2.2.8). If you don't use virtual hosts, try putting them in the <Directory> section for your document root.

1
  • I tried to put it in the just inside the <Directory /var/www/></Directory> and then just inside the <VirtualHost *:80></VirtualHost> section to no avail. I think I am going to go with ProxyPass and ProxyPassReverse directives.
    – user13146
    Jul 2, 2010 at 7:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .