views:

382

answers:

1

Hi there,

My hosting company recently upgraded me from Apache 1 to Apache 2, and I've started seeing some quite different behaviour with my mod_rewrite stuff.

Here's my .htaccess file:

DirectoryIndex blog.html

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # Rewrite current-style URLs of the form 'showpage.php?url=x'.
  RewriteRule ^(.*\.html)$ showpage.php?url=$1 [L,QSA]

</IfModule>

Now, previously with Apache 1, if you went to http://mysite.com/ then the DirectoryIndex would first take effect (http://mysite.com/blog.html) and then the RewriteRule would turn that into http://mysite.com/showpage.php?url=/blog.html

Now with Apache 2, if you go to http://mysite.com/blog.html it gets rewritten as expected, but if you go to http://mysite.com/ it serves you the vanilla blog.html file, without rewriting it to showpage.php. So the RewriteRule is being applied before the DirectoryIndex kicks in.

Besides adding an extra rule explicitly to catch the root page (which will be tedious since I'd have to take account of all subdirectories which also have a DirectoryIndex) does anybody know a way to make Apache 2 apply the RewriteRule after applying the DirectoryIndex?

A: 

Try this rule instead of the DirectoryIndex directive:

RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)/?$ $1/blog.html
Gumbo
i think he doesn't want to remove/replace the DirectoryIndex.
ax
@ax: Then he should first try it additionally to the `DirectoryIndex` directive.
Gumbo