Forum Moderators: phranque

Message Too Old, No Replies

Inconsistency using RewriteRule for Index.html

Problem in Apache 2.0, not in Apache 1.3

         

knowseek

6:33 pm on Nov 30, 2004 (gmt 0)

10+ Year Member



In a nutshell my problem is that our rewrite rule for
index.html only works when index.html is specified
in the URI. That is, [myservername.com...]
doesn't observe the rewrite rule but
[myservername.com...] does.
This did work as expected using Apache 1.3.

Here are the details. We are using Apache 2.0.50
on Redhat Linux. In httpd.conf we have:
DirectoryIndex index.html index.htm ...
AccessFileName .htaccess
<Directory "/var/docroot/testdir">
AllowOverride All
</Directory>
<VirtualHost *:80>
ServerName myservername.com
DocumentRoot /var/docroot
...
</VirtualHost>

In /var/docroot/testdir we have index.html,
.htaccess and test.html.

In .htaccess we have:
Options FollowSymLinks
RewriteEngine on
RewriteRule ^index\.html /testdir/test.html [R,L]

Without the rewrite rule, the URI
[myservername.com...] should process
index.html; with the rewrite rule it should process
test.html. This is how it works on our older
server using Apache 1.3.27. However, on our new
server with Apache 2.0.50 it ignores the rewrite
rule and processes index.html. Yet the URI
[myservername.com...] does
observe the rule and processes test.html while
replacing the displayed URI with
[myservername.com...]

Notes:
- The .htaccess file is being read - I have put
other commands in there and they are processed.
- The following do work in the .htaccess file:
"Redirect /testdir/index.html
[myservername.com...]
and
"DirectoryIndex /testdir/test.html index.html"
but we want to be able to use relative paths
and have the updated URI displayed.
- This problem applies to all directories where
we use an .htaccess file with RewriteRule for
index.html.

jdMorgan

8:05 pm on Nov 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DirectoryIndex can be applied on a per-directory basis or globally. You don't use a path, just the filename.
Make sure mod_dir is loaded on the server.

Altenately, you can modify the rule:


RewriteRule ^(index\.html)?$ /testdir/test.html [L]

This will work for a request for "/" or for "/index.html"

Jim

knowseek

9:12 pm on Nov 30, 2004 (gmt 0)

10+ Year Member



Thanks, Jim. Your RewriteRule line worked fine.