Using htaccess Rewrite

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm rewriting this:

To this:

Using this:

RewriteCond % !-f
RewriteCond %/index\.php !-f
RewriteCond % !-d

RewriteRule (.*)/(.*)/(.*) /$2/$3?var=$1&$ [QSA,NC,L]

This works fine until I add a third directory. Now, I'm wanting to
also redirect this:

To this:

I changed the rule to this:
RewriteRule (.*)/(.*)/(.*)/(.*) /$2/$3/$4?var=$1&$

Which worked on the third level, but then my pages on the second level
stopped working. I didn't look at the ENV variables, but I'm guessing
the rewrite was going to page//index.php, which doesn't exist.

Is there a better way to write this RewriteRule, and make it work for
a larger number of subdirectories?



Re: Using htaccess Rewrite

Quoted text here. Click to load it

For future readers, this works, but I know there's got to be a better
way. This simply doesn't allow for any growth:

# Check for 3rd level
RewriteCond % !-f
RewriteCond %/index\.php !-f
RewriteCond % !-d

RewriteRule (.*)/(.*)/(.*)/(.*) /$2/$3/$4?var=3D$1&%

# Else, Check for 2nd level
RewriteCond % !-f
RewriteCond %/index\.php !-f
RewriteCond % !-d

RewriteRule (.*)/(.*)/(.*) /$2/$3?var=3D$1&% [QSA,NC,L]

Also, I made a typo in my original post. That should have been %
, not $. That's fixed in this post.

Site Timeline