At 15:39 15-1-03, you wrote:
Hello

Is it possible to send all incoming requests to the same script within
PHP?
In other words: How can I get http://mysite/script.php to point to the
same script as http://mysite/anotherscript.php ? And is it possible to do
send a request like
http://mysite/someextrapathinfo to the same php script?
The background behind it is to create a controler that handles all
incoming requests and dispatches them to different worker scripts as
nessecary.
I think to achieve that you need to have a certain amount of rights, so you may have problems to get modules in Apache or .htaccess (see below) working when your ISP does not want to help you.

I've heard that Apache's mod_rewrite module can be very powerful in doing things like you propose.
But I had to find another way and i have now put a .htaccess file in the main directory of my website with a redirect in it:

ErrorDocument 404 /redirect/redirect.php

So this means that when people ask for a directory or file that does not exist, they do not get the standard 404 error message, but they are send on to the file www.mysite.org/redirect/redirect.php. BUT! it is very important that you do not write www.yourdomain.org because then you loose the information in the URL.

So then you come to the redirect.php file.

In this file you should see the original URL in $_SERVER['SCRIPT_URL']:

$path=trim($_SERVER['SCRIPT_URL']);

The way i did is was to use such links (Search Engine friendly!)
www.mysite.org/news/1224
www.mysite.org/researcher/SLanger

I would then split the URL at the slashes like this:

$path_bits=explode('/',$path);

And then i forward to the longer urls i normally use:

switch (strtolower($path_bits[1]))
{
case 'news':
Header("Location: http://www.sense.nl/modules.php?op=modload&name=News&file=article&mode=nested&order=0&thold=0&sid=".trim($path_bits[2]) );
break;

case 'researcher':
Header("Location: http://www.sense.nl/redirect/research.php?".trim($path_bits[2]) );
break;


default:
Header("Location: http://www.sense.nl/redirect/404.html";);

}



404.html would send real 404's to a polite message.




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to