mod_rewrite infinite rules?

Hi all.

I hope you can help. I'm not sure if this is even possible...

I'm using mod_rewrite to convert this:

into this:

using this line:

RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ page.php?level1=$1&level2=$2&level3=$3

via an .htaccess file in the website root.

Do any of you good people know of a way I could use this same technique for an unlimited number of levels of sub-pages and sub-sub-pages? In reality, it's unlikely that the page hierarchy will go further than 4 levels deep, but the CMS allows for an endless tree, so I need to accommodate this in the frontend if I can.

Any guidance would be appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I don't believe it's possible to achieve an indeterminate number of pattern captures using mod_rewrite. The redirect target has to be written explicitly, so there's no way that I know of which would allow you to have &levelX=$X in your target.

I have to say I'd avoid an unlimited pattern like the plague. Every one of those slashes looks like a subdirectory to Google and other search engines, and the deeper a subdirectory is, the lower the value Google tends to attach to its content.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
capnsplatterAuthor Commented:
Apologies for the delay responding.

Thanks for your help.

I had a feeling it wouldn't be possible.

I guess I'll just have to limit the number of levels to 3 or 4.
Yes, I would definitely recommend thinking about a more elegant way to restructure your site (and its URLs). That will keep things simpler, easier to maintain, and better looking from the point of view of visitors, and web crawlers.
capnsplatterAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Services

From novice to tech pro — start learning today.