Re: Redirect based on URL
| From: | Kurth Bemis | Date: | Thu, 17 Aug 2000 07:11:53 +0000 |
| Subject: | Re: Redirect based on URL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-12144@lists.php.net to get a copy of this message | ||
At 03:56 PM 8/17/2000 +1200, Matthew Delmarter wrote:
Hello all, I would really appreciate some help on this one. I am developing a site that stores listings of tour operators in a database. A tour operator can also have their own page on the site - but again it will be stored in a database. What I want to know - is there a nice way to find a tour operators page within the site without having to enter messy paths and query strings? EG instead of typing: www.mydomain.com/tours/list.php?id=2 or www.mydomain.com/tours/list.php?name=gannetsafaris I would prefer something like: www.mydomain.com/gannetsafaris and having it redirect; or something liketo get the above use something like this ------------------snip----------------- $requested_page = getenv("PATH_INFO"); // get rid of the initial forward slash from the path_info $requested_page = ereg_replace("^/", "", $requested_page); $include_dir = "/path/to/include/dir"; $allowed_pages = array(
"main",
"search",
"aboutus",
"specials",
//etc, etc
);
// loop through the list of allowed pages, checking to see if
// the requested page is one of the allowed pages
foreach ($allowed_pages as $this_page) {
if ($this_page == $requested_page) {
$page_to_include = $this_page;
break; // stop looping since $this_page is allowed
}
}
if (!$page_to_include) { // if the requested page wasn't on the list of
approved pages...
$page_to_include = "404"; // then display a 404 message} $include_file = "$include_dir/$page_to_include.html"; if (!file_exists($include_file)) {
// if the file doesn't exists, display an error message
echo "404 not found<br>The include file
(".htmlentities($include_file).") was not found.";
} else {
// otherwise include it
include $include_file;
}
---------------------snip------------------ (brucex.r.christensen@intel.com wrote the code for me, kurth)
www.mydomain.com/?page=gannetsafaristo get this make the page that does the work named index.php and make sure that index.php in your httpd.conf is in your DirectoryIndex entry...... then the above would really be /index.php?page=blahblah did i confuse you? ~kurth
How do I get this to work? Is there a better way? Regards, Matthew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.netKurth Bemis - Senior Linux Network/Systems Administrator, USAExpress.net kurth@usaexpress.net http://www.usaexpress.net/kurth ICQ - 6624050 Call Sign - N1TYW PGP key available - http://www.usaexpress.net/kurth/pgp Fight Weak Encryption! Donate your wasted CPU cycles to Distributed.net (http://www.distributed.net)