Forum Moderators: phranque

Message Too Old, No Replies

mod alias & mod rewrite modules fail to start

Newbie to Apache and these modules

         

wkczm

4:11 am on Aug 31, 2007 (gmt 0)

10+ Year Member



Hello,

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

wkczm

1:19 pm on Aug 31, 2007 (gmt 0)

10+ Year Member




Ok I found one stupid mistake, I've now set the AllowOverride to All (it was None). Now .htaccess should be processed.

Still have the same behavior:

lynx www.domain.ca/page1.html
- shows page 1 and does not log anything.

jdMorgan

2:03 pm on Aug 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Question: Are you completely flushing your browser cache between tests? If not, the page will be served from cache, and no request will be sent to your server. This should be clearly indicated by the lack of any requests from your browser in the server access log.

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

wkczm

6:07 am on Sep 1, 2007 (gmt 0)

10+ Year Member



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

jdMorgan

2:29 pm on Sep 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, a further detail that's in your way to finding the problem: You may not use RewriteLog-related directives in .htaccess; Their use is restricted to the server config file level. Check the "Context" description of each directive before trying to use it, especially in .htaccess.

I'd be looking at AllowOverride and Options settings very carefully, here.

Jim

wkczm

6:50 pm on Sep 1, 2007 (gmt 0)

10+ Year Member



Great Jim thanks,

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]

wkczm

6:51 pm on Sep 1, 2007 (gmt 0)

10+ Year Member



ps I'll be away and probably not able to reply for at least 2 days. thx.

jdMorgan

7:01 pm on Sep 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In httpd.conf or conf.d, you'll need to specify the full URL-path, as documented:

RewriteRule [b]^/p[/b]age1\.html$ http://www.example.ca/page2.html [R=301,L]

In .htaccess per-directory context, the path to the .htaccess file's directory is stripped, so the leading slash is not visible to RewriteRule in a "top-level" .htaccess file. But at the server config level, the full path is present.

Jim

wkczm

8:05 pm on Sep 1, 2007 (gmt 0)

10+ Year Member




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

jdMorgan

11:30 pm on Sep 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




strip per-dir prefix: /var/www/page1.html -> page1.html

applying pattern '^/page1\.html' to uri 'page1.html'

pass through /var/www/page1.html


These messages imply that this "000-default" file (whatever it is--because I've never heard of it), is treated as an .htaccess file. Therefore, the pattern will not require the leading slash, and should match if you omit it.

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