On May 5, 4:46*am, "cel...@gmail.com" <cel...@gmail.com> wrote:
> Hi all,
>
> I am pretty much a PHP developer and I have a new idea for my website.
> To implement the new idea I guess I need some basic configuration on
> apache.
> I have my index.php and everything runs depend on that file. Now I
> want to manage any other requests on root directory other than the
> index.php is handled.
> For example:
> for now,www.mydomain.com/index.php?foo=baretc. works as expected
> but I want any other requests likewww.mydomain.com/bla,http://www.mydomain.com/qwerty,www.m....com/dangerare hadled somehow.
> I suppose there should be a solution like handling any requests "which
> is not handled as usual"
> for example if I have some php file in some directory likewww.mydomain.com/somedir/somefile.phpit should be run as expected but
> lets say if I don't have "thisfiledoesntexist" in my directory
> structure likewww.mydomain.com/thisfiledoesntexist, this request
> should be handled by lets say another php script calledwww.mydomain.com/unhandled.php
>
> can you suggest anything?
>
> Cheers
> Baris
i'd recommend against having all files in your root htdocs directory
run off mod_rewrite since you said you wanted some files in
subdirectories to load normally without rewriting rules. if you want
to go this route though, you should probably send all requests through
a single php file:
1) enable mod_rewrite on / in httpd.conf, e.g.:
<Directory "/">
RewriteEngine on
RewriteBase /
RewriteRule ^(.+)$ /handler.php?r=$1
</Directory>
2) create a php file that handles all requests, e.g.:
<?php
switch ( $_GET['r'] ):
case "something": require_once('assets/something.php'); break;
case "something_else": require_once('assets/something_else.php');
break;
default:
if ( file_exists($_SERVER['DOCUMENT_ROOT'] . "/" . $_GET['r']) ) {
require_once($_SERVER['DOCUMENT_ROOT'] . "/" . $_GET['r']);
} else {
require_once($_SERVER['DOCUMENT_ROOT'] . '/unhandled.php');
}
break;
endswitch;
?>