Forum Moderators: phranque

Message Too Old, No Replies

.htaccess

         

premasagar

3:53 pm on Aug 26, 2006 (gmt 0)

10+ Year Member



[edit]Sorry for the vague post title - I meant to change it before posting, but forgot...[/edit]
--

I've read related posts and tried to adapt them, but I could use some extra brain cells on this:

I want to change this:
www.example.com/myfolder/first/second/third

To this:
www.example.com/template.php?folder=myfolder&page=first_second_third.php

And this:
www.example.com/myfolder/first/

To this:
www.example.com/template.php?folder=myfolder&page=first.php

And this:
www.example.com/myfolder/

To this:
www.example.com/template.php?folder=myfolder&page=index.php

--

The Logic:
1) If the directory is 'myfolder' (or another specified folder), then...

2) If there is no further sub-directory, then the 'page' is index.php...

3) If there is a further sub-directory, then for each sub-directory replace the slashes with underscores and add '.php' to get the page name

4) Check if the page produced actually exists (by using the -f flag)

5) If it does exist, then redirect to the template page: www.example.com/template.php?folder=myfolder&page=page

6) If it doesn't exist then give 404

- The request url will always be at least "www.example.com/myfolder/first" but may have any amount of further sub-directories. I could limit this to five sub-directories if that makes it a lot easier, as it's unlikely to exceed this in practice.

- The request url may or may not end with a trailing slash.

--

What I have so far:
I am trying to progressively change the relevant slashes to underscores:
RewriteRule ^(myfolder¦myOtherFolder)/([^/]+)/([^/]+)/?$ $1/$2_$3 [N]

And then send the result to the template page:
RewriteRule ^(myfolder¦myOtherFolder)/(.*?)_?$ template.php?section=$1&path=$2 [L]

--

These rules are not complete and I am confused!
Any help would be greatly appreciated.
Premasagar.