views:

56

answers:

1

I am cleaning up a large .htaccess file containing a lot of mod_rewrite statements.

The biggest part of the clutter comes from statements catching various occurrences of

/directory1
/directory1/directory2
/directory1/directory2/directory3

using statements like

RewriteCond  %{REQUEST_URI} ^/([^/]+)/([^/]+)$   
RewriteRule .* /front.php?level1=%1&level2=%2&%{QUERY_STRING} [L]

RewriteCond  %{REQUEST_URI} ^/([^/]+)/([^/]+)/([^/]+)$   
RewriteRule .* /front.php?level1=%1&level2=%2&level3=%3&%{QUERY_STRING} [L]

could somebody versed with mod_rewrite give me a pointer on how to write one universal statement that will catch any depth of directory1/directory2... and put the appropriate level variable into the RewriteRule?

+2  A: 

Rather use the following rewriterule

RewriteRule ^(.*)$ front.php/$1 [L]

and access folders by pathinfo in front.php:

$pathinfo = $_SERVER['PATH_INFO'];

You can alternatively also enable MultiViews in Apache and configure it to use front.php as index file instead and grab pathinfo the same way.

BalusC
Good idea, and no problem performance wise because what gets caught by this, will be run through the PHP script no matter what. This will be an application built to run on as many platforms as possible, so I don't want to have a dependency on MultiViews. What I'm using now is `RewriteRule ^dirname/(.*)$ dirname/index.php?request=$1%{QUERY_STRING} [L]` Cheers!
Pekka