-3

How do i use index.php in main folder to show content for different sub directories in that folder?

Ex :

/members/
/members/index.php
/members/change-password/
/members/change-email-address/

Is it possible? I want to keep the urls clean instead of using index.php?change-password

EDIT : The possible duplicate only shows how to get sub directories, I also need a way to use the index.php in main folder when someone visits the sub folders.

Srikanth Koneru
  • 264
  • 1
  • 3
  • 13

2 Answers2

2

Use htaccess for this eg

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^/members/change-password/$ ./index.php?change-password [NC] 

You can find more, if you search on internet.

Gaurav Rai
  • 900
  • 10
  • 23
  • small change was needed `Options +FollowSymlinks RewriteEngine On RewriteRule ^change-password/$ index.php?change-password [NC] ` the `/` should be removed it seems. – Srikanth Koneru Dec 15 '15 at 14:16
0

From PHP Get all subdirectories of a given directory:

$dirs = array_filter(glob('*'), 'is_dir');
print_r( $dirs);

Recursively:

function getAllSubDirectories( $directory, $directory_seperator ){
   $dirs = array_map( function($item)use($directory_seperator){ return $item . $directory_seperator;}, array_filter( glob( $directory . '*' ), 'is_dir') );

    foreach( $dirs AS $dir ) {
        $dirs = array_merge( $dirs, getAllSubDirectories( $dir, $directory_seperator ) );
    }

    return $dirs;
}
Community
  • 1
  • 1
Ben
  • 8,894
  • 7
  • 44
  • 80