Forum Moderators: phranque

Message Too Old, No Replies

Recursive .htaccess

Is it possible to do recursion in an htaccess file?

         

Ben_Johnson

9:33 pm on Apr 22, 2006 (gmt 0)

10+ Year Member



Here is my .htaccess file:

# Enable mod_rewrite, start rewrite engine
Options +FollowSymLinks
RewriteEngine on

#
# Internally rewrite search engine friendly static URL to dynamic filepath and query
RewriteRule ^([^/\\.]+)/([^/\\.]+)/([^/\\.]+)/([^/]+)/([^/\\.]+)/([^/]+)/([^/\\.]+)/([^/]+)/([^/\\.]+)/([^/]+)/?$ /index.php?controller=$1&controller_action=$2&$3=$4&$5=$6&$7=$8&$9=$10 [L]
RewriteRule ^([^/\\.]+)/([^/\\.]+)/([^/\\.]+)/([^/]+)/([^/\\.]+)/([^/]+)/([^/\\.]+)/([^/]+)/?$ /index.php?controller=$1&controller_action=$2&$3=$4&$5=$6&$7=$8 [L]
RewriteRule ^([^/\\.]+)/([^/\\.]+)/([^/\\.]+)/([^/]+)/([^/\\.]+)/([^/]+)/?$ /index.php?controller=$1&controller_action=$2&$3=$4&$5=$6 [L]
RewriteRule ^([^/\\.]+)/([^/\\.]+)/([^/\\.]+)/([^/]+)/?$ /index.php?controller=$1&controller_action=$2&$3=$4 [L]
RewriteRule ^([^/\\.]+)/([^/\\.]+)/?$ /index.php?controller=$1&controller_action=$2 [L]
RewriteRule ^([^/\\.]+)/?$ /index.php?controller=$1 [L]

Notice the pattern. Is it possible to do recursion in this file to handle this?

jdMorgan

2:12 am on Apr 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do recursion in .htaccess, but it involves re-starting the mod-rewrite engine and scanning your entire .htacess file all over again. It is highly inefficient, even compared to running a dozen rules of the form you're using here.

If you want to experiment with it, see the [N] and [E] flags -- [N] to restart, and [E] to set environment variables to 'pass yourself notes' about previous passes through the code.

The only thing I've found this method useful for in several years is that it's the only way to do mass character-replacement in an .htaccess context. In server config contexts, it's much easier to use RewriteMap to call a script.

Jim

Ben_Johnson

6:41 am on Apr 23, 2006 (gmt 0)

10+ Year Member



Thanks JD. It's people like you that make this forum great.