Forum Moderators: phranque
I'm pretty much a newb to Apache, but know unix/linux quite well. I've spent many hours trying to get rewrite working and haven't found any google posts exactly like the problem I'm seeing.
My problem is that even though the modules are being loaded (at least to me they look like it), they do not seem to be working. The rewritelog directive does not record anything in it's log file in all the (many) examples I've tried from the net and from my own fiddling.
My apache2 version is:
(Server Version: Apache/2.2.3 (Ubuntu) PHP/5.2.1 mod_ssl/2.2.3 OpenSSL/0.9.8c)
The mod_alias and mod_rewrite modules appear to load because apache2.conf contains:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
Include /etc/apache2/ports.conf
Include /etc/apache2/conf.d/
Include /etc/apache2/sites-enabled/
And modules seem to load from mods-enabled dir:
mod_alias:
/etc/apache2/mods-enabled/alias.load:LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so
mod_rewrite:
/etc/apache2/mods-enabled/rewrite.load:LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
I have gone to the simplest test case and am using the nice examples provided at: [webmasterworld.com...] My .htaccess file from the root folder is:
.htaccess:
#RedirectMatch page1\.html page2.html
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^page1\.html$ page2.html [R=301,L]
rewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 9
All tests are on a ssh putty session to the webserver (no firewall issues), with lynx. I restart apache2 whenever .htaccess changes.
I test the redirectmatch rule first (remark other lines out):
lynx www.domain.ca/page1.html
- lynx displays page1 not page2
I test rewrite rules next (remark redirectmatch out):
lynx www.domain.ca/page1.html
- lynx displays page1 not page2
- log file rewrite.log - contains NOTHING! And I've NEVER got it
to log anything in all my testing.
Log file permissions look ok as error.log and access.log have the same ownership:
-rw-r--r-- 1 root adm 0 2007-08-29 13:35 /var/log/apache2/rewrite.log
Apache processes are:
root 4227 1 0 19:27? 00:00:03 /usr/sbin/apache2 -k start
www-data 4561 4227 0 21:21? 00:00:00 /usr/sbin/apache2 -k start
www-data 4562 4227 0 21:21? 00:00:00 /usr/sbin/apache2 -k start
www-data 4563 4227 0 21:21? 00:00:00 /usr/sbin/apache2 -k start
www-data 4564 4227 0 21:21? 00:00:00 /usr/sbin/apache2 -k start
www-data 4565 4227 0 21:21? 00:00:00 /usr/sbin/apache2 -k start
apache2ctl -l
- I believe mod_alias and mod_rewrite are contained in mod_so.c
Compiled in modules:
core.c
mod_log_config.c
mod_logio.c
prefork.c
http_core.c
mod_so.c
I'm still not exactly sure how .htaccess works and when the directives in it get processed. I am probably missing some fundamental concept here so any help would be most appreciated.
thanks
Also, note that a server restart is not needed following .htaccess file changes; Since .htaccess is interpreted for each and every HTTP request, the restart needed to re-compile httpd.conf code is unnecessary when only .htaccess files have changed.
Jim
Thanks for your reply, I was not clearing the cache, but am now before each test. Tests below using firefox flushing before each try (or 'lynx -reload url') does not rewrite page1 to page2. Details from access file for firefox tests:
10.10.10.1 - - [01/Sep/2007:00:43:25 -0500] "GET /page1.html HTTP/1.0" 200 70 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
10.10.10.1 - - [01/Sep/2007:00:43:25 -0500] "GET /favicon.ico HTTP/1.0" 404 326 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
10.10.10.1 - - [01/Sep/2007:00:43:36 -0500] "GET /page2.html HTTP/1.0" 200 64 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
10.10.10.1 - - [01/Sep/2007:00:54:45 -0500] "GET /favicon.ico HTTP/1.0" 404 326 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
- still nothing logged in rewrite log:
-rw-r--r-- 1 root adm 0 2007-08-29 13:35 /var/log/apache2/rewrite.log
And code in .htaccess is (thanks for your explanation didn't understand how it worked):
#RedirectMatch page1\.html page2.html
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^page1\.html$ page2.html [R=301,L]
rewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 9
I'm still swimming in sand.
thanks,
Warren
I'd be looking at AllowOverride and Options settings very carefully, here.
Jim
I think I'm getting it, but it's not totally working yet.
It's fine from lynx, rewrites page1 as page2, and logs activity.
I've disabled AllowOverride in apache2.conf, moved rewrite directives from .htaccess into 000-default under /var/www directory directive, and that fixed the problem, page1 resolves to page2 in lynx. The activity is logged. Here's the 000-default file in sites-enabled:
<VirtualHost>
...
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
RewriteEngine on
RewriteRule ^page1\.html$ http://www.example.ca/page2.html [R=301,L]
</Directory>
...
rewritelog "/var/log/apache2/rewrite.log"
rewriteloglevel 9
</VirtualHost>
Still not working:
I clear the cache in ff (clear cache then restart ff), but page1 still resolves to page1, and there is nothing written to the log for this event.
Any ideas?
thanks,
Warren
[edited by: jdMorgan at 7:07 pm (utc) on Sep. 1, 2007]
[edit reason] example.ca [/edit]
RewriteRule [b]^/p[/b]age1\.html$ http://www.example.ca/page2.html [R=301,L]
Jim
Wow, thanks for that knowledge.
It's working now for lynx, ff, ie, but odd thing is, rewrite is not using regex, it's matching to a clear text pattern. Here's the rule that works for me:
RewriteRule page1.html [issd17.ca...] [R=301,L]
I tried several regex rules:
RewriteRule ^/page1\.html$ http://www.example.ca/page2.html [R=301,L]
RewriteRule '^/page1\.html$' http://www.example.ca/page2.html [R=301,L]
RewriteRule "^/page1\.html$" http://www.example.ca/page2.html [R=301,L]
RewriteRule page1\.html http://www.example.ca/page2.html [R=301,L]
They returned similar errors and displayed page1 (these log msgs are from the rule,
RewriteRule ^/page1\.html [issd17.ca...] [R=301,L]):
10.10.10.1 - - [01/Sep/2007:14:53:45 --0500] [www.issd17.ca/sid#8140f28][rid#8462598/initial] (3) [perdir /var/www/] strip per-dir prefix: /var/www/page1.html -> page1.html
10.10.10.1 - - [01/Sep/2007:14:53:45 --0500] [www.issd17.ca/sid#8140f28][rid#8462598/initial] (3) [perdir /var/www/] applying pattern '^/page1\.html' to uri 'page1.html'
10.10.10.1 - - [01/Sep/2007:14:53:45 --0500] [www.issd17.ca/sid#8140f28][rid#8462598/initial] (1) [perdir /var/www/] pass through /var/www/page1.html
I know there shouldn't be any directive/command to turn regex on/off for apache, but looked anyway .. and found none.
Any ideas?
thx
Warren
strip per-dir prefix: /var/www/page1.html -> page1.htmlapplying pattern '^/page1\.html' to uri 'page1.html'
pass through /var/www/page1.html
There are many odd server configurations in the world, and this appears to be one of them. Regex is built into the OS, and isn't something that can be turned on or off -- although the library can become corrupted and cause the machine to crash.
Jim