[thesite] mod_rewrite trickery (was: What's appropriate for d.e.o.)

Arthur Noel arthur at arthurnoel.com
Sun Aug 19 12:18:01 CDT 2001

> I know you can fiddle with the types a bit to
> get something a bit nicer like:
> http://dir.evolt.org/directory/coding/client-side/css/
> but I'd rather exclude that extra level all together if possible.
> If you know of any way of doing what I'm trying to do with
> then that would be great!

I've used the following with some success. In httpd.conf

ErrorDocument 404 /wrapper.php
RewriteEngine on
RewriteCond %{REQUEST_URI} !\.css$
RewriteCond %{REQUEST_URI} !\.js$
RewriteCond %{REQUEST_URI} !\.jpg$
RewriteCond %{REQUEST_URI} !\.gif$
RewriteCond %{REQUEST_URI} !\.txt$
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule /(.*) /wrapper.php/$1  [PT]	

where wrapper.php sits in the document root and contains the following:

$temp = ereg_replace("(.*)(\?.*)$", "\\1", $REQUEST_URI); // strips off
any query string
$temp = ereg_replace("(.*/.*)(\..*)$", "\\1", $temp); // strips off file
extension i.e. ".html"
$temp = ereg_replace("(.*)(/)$", "\\1", $temp); // strips off trailing
$temp = ereg_replace("^(/)(.*)", "\\2", $temp); // strips off leading
$temp = strtolower($temp);
$path_vars = split("/", $temp);

which gives you an array $path_vars so that if the request was
http://dir.evolt.org/coding/client-side/css/ you'd have 

$path_vars[0] == "coding"
$path_vars[1] == "client-side"
$path_vars[2] == "css"

don't know if that's any good to you


More information about the thesite mailing list