PDA

View Full Version : Restricting search results by URL at the search form level


innerfire
07-30-2005, 10:55 PM
I know that this has been talked about a few times in the forum, and I have read through all posts, but know body has asked this specific question as far as I can tell. My site is broken up by different languages via sub-directories, for example, es.mysite.com and de.mysite.com. However, my search results once all domains are spidered are mixed. So, from each language area I want to restrict results to that sub-domain (which phpdig treats as a unique URL, which I like, thus making this much more easy). What is the code to simply add this variable into the form? I don't want the form on en.mysite.com to show results for anything other than en.mysite.com. I don't need any option buttons, just need to know how to pass the restriction along to the rest of the program (my php skills suck).

Charter
07-31-2005, 08:58 AM
Try the following...

In search.php find:

if (ALLOW_RSS_FEED) {

And beforehand add:

if (!empty($_SERVER['HTTP_HOST']) && (empty($site) || $path == '-###-')) {
if (empty($site)) {
$temp_site = addslashes("http://".$_SERVER['HTTP_HOST']."/");
$temp_query = mysql_query("SELECT site_id FROM ".PHPDIG_DB_PREFIX."sites ".
"WHERE site_url = '$temp_site' LIMIT 1",$id_connect);
$temp_row = mysql_fetch_row($temp_query);
$site = $temp_row[0];
}
$path = '';
}

innerfire
07-31-2005, 07:11 PM
That almost worked. Now when I search from either
es.symptoms101.com or www.symptoms101.com the results are only being shown from www.symptoms101.com (english). Eventually this site will have Spanish, German, Italian, French, and maybe portuguese, so begin able to keep the sub domain results separate would be great when searching from the sub domain itself. So, the results of the above change are that all results are being shown in english, sourcing from www.symptoms101.com (which is where the search program is located).

A more confusing twist, and I don't understand the technicality of it, may be that the system is creating subdomains by making folders within www.symptoms101.com for example, es.symptoms101.com is located on the server at www.symptoms101.com/es/. That is why I was asking about specifying the "sub domain" via the form. Any ideas on how to make it work? The site is set up now with the two subdomains and the search is coded with your suggested changes (99.9% of my traffic is english speaking until the rest of the site gets spidered, probably in a week or so).

P.S. Love the smileys on this forum!

Charter
08-01-2005, 08:36 AM
Set a PHP info page in the es subdirectory:

<?php phpinfo(); ?>

And call the PHP info page from a browser. Look for es.symptoms101.com on the page. Is it by HTTP_HOST or something else?

The code above was to attempt to get the correct site_id depending on what (sub)domain the user entered prior to searching, without having to change the HTML form on each page.

You might try using the following in the HTML form instead:

<input type='hidden' name='site' value='XX'/>
<input type='hidden' name='path' value=''/>
<input type='hidden' name='refine' value='1'/>

Where XX is the site_id number from the sites table.

You might may to tweak the HTML like so:

<input type='hidden' name='site' value='XX'/>
<input type='hidden' name='path' value='es/'/>
<input type='hidden' name='refine' value='1'/>

If the URLs in the sites table are www instead of subdomains.