Originally posted by ajdegans
But i realized that searchengines scope for urls to put in the ranking lists. So (if my thinking is right) the search engine is able to grab file urls on a server.
That is kind of correct - search engines find files by crawling hyperlinks. If a file has no crawlable links, the SE cannot find it.
Basicaly what i want to know is how do i prevent people from entering my site on another page than index.php. And if they do enter on, let's say, navigatie.php whats the smartest way to redirect them to the index.php.
To me, the more important question here is not how can you do this but why would you do this? If the page the SE brings up is relevant to the users search, why not let the user land on that page and find what they are looking for? I know if I click on a search result and don't relatively immediately find what I expected to, I usually close that site and go to the next SE result. For example, if you are selling widgets, and I am looking for specifically a red and green widget. I do a search for red and green widgets and your red and green widgets page comes up. I click on the link in the results, and I am redirected to your home page instead of getting your red and green widgets page. I scan the homepage, see that you sell widgets but nothing specific on red and green ones. So I close the window and try the next result.....is that what you want to do????
Ok, I realize I didn't really answer your questions above. So...
Razz is correct in recommending using a session or cookie to set a variable that says "index.php has been visited!" when a user visits your homepage. Then, each page after that can check and see if the user has visited the homepage and if so, go ahead and load, and if not, redirect them to index.php. If what Razz and I have said doesn't make sense to you, a good place to start is here: http://www.phpfreaks.com/tutorials/41/0.php .
Example of code on index.php:
session_start()
$_session['home_page_visited'] = 'yes';
Example of code on other pages:
session_start()
if ($_session['home_page_visited'] != 'yes') {
header ("location: [url]http://www.mysite.com/index.php/[/url]");
exit ;
}
Ok, now another word of caution...if you do this, you will keep the search engine from crawling your site. Bots do not accept cookies and generally won't crawl url's that have SID's appended to them. One option is to check the user agent and see if it is a SE bot and if so, don't start the session. Example:
// Use this to start a session only if the UA is *not* at search engine
$searchengines=array("Google", "Fast", "Slurp", "Ink", "Atomz", "Scooter", "Crawler", "bot", "Genius");
$is_search_engine=0;
foreach($searchengines as $key => $val) {
if(strstr("$HTTP_USER_AGENT", $val)) {
$is_search_engine++;
}
} if($is_search_engine==0) {
// visitor is not a search engine - start the session
session_start();
//You can put anything else in here that needs to be hidden from search engines
} else {
// visitor is a search engine - Put anything you want only a search engine to see in here
}
Hope that helps.