Back to mnoGoSearch site


mnoGoSearch 3.2.43 reference manual: Full-featured search engine software
PrevChapter 7. Languages supportNext

Making multi-language search pages

Original idea instructions by Craig Small . Some minor changes by Alex Barkov .

It is often required to allow for different languages, which means different search.htm files depending on what language users have set in their browser.

Please note that configuration issues given below are absolutely the same for both search.php and search.cgi front-ends.

Note: PHP specific issues: the only thing to be done in search.php is a hack in config.inc to change the template file:


$template_file= ereg_replace(".php", ".htm", basename(getenv("SCRIPT_FILENAME")));
$template_file = "/etc/somewhere" . $template_file;

Further installation should be done in three steps.

  1. Installing several templates.

    The general idea is to have one search.php or search.cgi file and then many search.[language].htm files. You also have a search.htm file (usually a symlink to search.en.htm) as default file.

    If the name of the script is search.en.php (or search.en.cgi) then both CGI and PHP front-ends will be looking for /somewhere/etc/search.en.htm assuming that /somewhere/etc/ is /etc/ directory of mnoGoSearch installation.

    You would then populate /somewhere/etc/ with all the search.htm files so /somewhere/etc has:

    search.en.htm English template
    search.pl.htm Polish template
    search.ru.htm Russian template
    search.htm Symlink to English template

  2. Installing front-ends

    Create a directory and put search.cgi or search.php there (along with the include files if you want, but I fiddle with the php include_path and put them elsewhere).

    Then setup the symlinks:

    search.cgi Original file
    search.en.cgi symlink
    search.pl.cgi symlink
    search.ru.cgi symlink

    Or in the case of PHP front-end:

    search.php Original file
    search.en.php symlink
    search.pl.php symlink
    search.ru.php symlink

  3. Configuring Apache

    Then you need to make Apache understand what weirdness you are doing here. So you need to get negotiation happening and some magic with the indexes. I used .htaccess file but you could stick it in the Apache config itself.

    
AddLanguage en .en
    AddLanguage pl .pl
    AddLanguage ru .ru
    
    DirectoryIndex search search.cgi  (or search.php)
    Options FollowSymlinks MultiViews
    

How does it work?

  1. You type the url http://myhost/mydir/search no slash at end !!

  2. Your browser says "I like English (well language negotiation en) "

  3. Apache finds search.en.cgi (DirectoryIndex gives search, MultiViews gives the en.cgi)

  4. The SCRIPT_FILENAME which is used in both search.cgi and search.php is somepath/search.en.cgi

    Note: Most other variables will give the wrong result, either search or search.cgi)

  5. Your hack in config.inc means you will use search.en.htm.

So what happens if the user wants, say, German? Well there is no search.de.cgi (search.de.php) so the first bit of DirectoryIndex fails, so it tries the second one, search.php OK, they get the page in English, but it's better than a 404.

This does work, you may need some more Apache fiddling to get negotiation to work because I am testing this on a server that already has it setup, so I may have missed something.

Possible troubles

You may get some language negotiation problems caused by:

The Apache team is working on some workarounds for most of these, if possible. For a reasonably heavily used website you can expect an email about it once a week or so.