Page 1 of 1

process all page requests by one file

Posted: Fri Nov 12, 2004 11:12 pm
by cesine
i'm not sure how to ask my question but here's a shot.

i want to process (i think all) requests to my server (apache) by a php file. the file would call to include a menu, a login, a comments file, and the file requested. i suppose one way to do this would be to have apache always redirect to this php file, passing in the requested file's name? i could do this with the missing file option

im looking for the easiest and least-silly way of doing this.. i could make all my pages redirect to the missing file.. and then have the missing file process the request.. but that seems silly

am I silly for wanting to do this.. whats a better way. i havent found many answers because i dont know what im searchign for? are people already doing this.. waht do they call it...

Posted: Fri Nov 12, 2004 11:49 pm
by kettle_drum
If i understand your question fully you want to load all pages on your site from one single page - i.e. all requests go to index.php, but depending on an added variable it will show a different page to the user. This is very common and very easy to do. There is lots of threads in the forum that discus doing this but as a quick tip...

page called: index.php?page=contact

Code: Select all

if(isset($_GET['page'])){
   include('some/path/'.$_GET['page'].'.php');
}else{
   include('some/path/home.php');
}
Then you will want to get more complex and check the file that the user is requesting to make sure its ok to show them it, and add more error checking etc. But that is the basic principle of it. Just include that code in the page template and then the page will always look the same - just with a different main content. You can then do the same with the menus if you wish.

Posted: Sat Nov 13, 2004 1:10 am
by cesine
yes actually that is waht im doing now, but i dont have a way of sending all page requests, or file requests through my index.php should i just rename my files to .inc so they wont "exist" and then have all page not found errors handled by my index.php.. isnt there a smarter way of doing this? do i realy want to do this? what are reasons not to...

Posted: Sat Nov 13, 2004 2:22 am
by timvw
as said before, search the web for "front controller".

you could use apache's mod_rewrite to map all all request to a given page.

Posted: Sat Nov 13, 2004 2:46 am
by kettle_drum
You could add a RedirectMatch to the httpd.conf file.