mod_rewrite and DirectoryIndex

#1
Hello

I just installed the trial version of the enterprise product. My organization is looking for an efficient way to run both PHP4 and PHP5 sites on a single server, and Litespeed allows us to do this easily, with additional performance and security.

Upon installation, however, we've noticed some of our custom mod_rewrite rules are no longer functioning:

Code:
RewriteEngine On
RewriteBase /

DirectoryIndex index.php index.html index.htm default.htm default.html /index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
Explained quickly: If a URL is accessed that doesn't have a an existing file, it's handled by index.php in the root folder.

All seems to be working, except for the /index.php call at the end of the DirectoryIndex directive. On Apache, when a URL that ends with a / slash is requested, and no index file is found, the index.php script in the root folder is called.

As I mentioned, this works well with Apache, but doesn't seem to work with Litespeed.

Any advice is appreciated.
 

mistwang

LiteSpeed Staff
#2
DirectoryIndex /index.php
has not been implemented in LSWS. We will add that implementation.
Is that a plain redirect, or some special variables added in Apache?

How about changing your rewrite rule to

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.php [L]
I think the rewrite rule is duplicate with "/index.php".
 
#4
The rewrite rule won't execute because the directory exists.

So if a directory is requested without an index file, then /index.php in DirectoryIndex gets called.

From http://httpd.apache.org/docs/1.3/mod/mod_dir.html:

Note that the documents do not need to be relative to the directory;

DirectoryIndex index.html index.txt /cgi-bin/index.pl

would cause the CGI script /cgi-bin/index.pl to be executed if neither index.html or index.txt existed in a directory.
 
#9
Unfortunately *ErrorDocument* doesn't work either.

1. Directory requests still don't work.
2. All other requests come back as intended, but the headers return 404, which isn't good.

You've piqued my curiosity, I'm going to try something different and report back.
 
#10
Ok, some interesting results.

I think I might have found a way to emulate the DirectoryIndex directive with Litespeed.

As an Apache directive:

Code:
DirectoryIndex index.php index.html index.htm default.htm default.html /index.php
Can be expressed as a rewrite rule on Litespeed:

Code:
DirectoryIndex index.php index.html index.htm default.htm default.html 

RewriteCond %{REQUEST_URI} ^(.*)/(\?.*)?(\#.*)?$
RewriteCond %{DOCUMENT_ROOT}/$1index.php !-f
RewriteCond %{DOCUMENT_ROOT}/$1index.html !-f
RewriteCond %{DOCUMENT_ROOT}/$1index.htm !-f
RewriteCond %{DOCUMENT_ROOT}/$1default.htm !-f
RewriteCond %{DOCUMENT_ROOT}/$1default.html !-f
RewriteRule ^(.*) index.php [L]
What it does is it looks for URLs ending in a slash (but ignoring query strings (?) and achors (#)), and checks if an index file exists. If not, it rewrites to the bootstrap file in /index.php.

In my quick tests everything seems to work well in both Apache and Litespeed.
 

mistwang

LiteSpeed Staff
#12
I think I might have found a way to emulate the DirectoryIndex directive with Litespeed.
Not necessary with 3.3.5 release any more, native implementation has been added.

Code:
DirectoryIndex index.php index.html index.htm default.htm default.html 

RewriteCond %{REQUEST_URI} ^(.*)/(\?.*)?(\#.*)?$
RewriteCond %{DOCUMENT_ROOT}/$1index.php !-f
RewriteCond %{DOCUMENT_ROOT}/$1index.html !-f
RewriteCond %{DOCUMENT_ROOT}/$1index.htm !-f
RewriteCond %{DOCUMENT_ROOT}/$1default.htm !-f
RewriteCond %{DOCUMENT_ROOT}/$1default.html !-f
RewriteRule ^(.*) index.php [L]
It works, but not as efficient.
It should be a non-issue with our official 3.3.5 release, anyway.
 
Top