Merlin <news.letters.DeleteThis@web.de> writes:
> thank your for your help. You wrote that it is possible via apache and
> the browser language to redirect traffic.
> This is exacly what I am searching for. I am launching a german site
> while the english one exists now for quite a while. Now I would like to
> redirect the german community members to the new german site, or even
> better give them a popup with the info that a german site is available.
>
> I tryed to understand what the apache docs said here:
<font color=green> > > <a style='text-decoration: underline;' href="http://httpd.apache.org/docs-2.0/content-negotiation.html</font" target="_blank">http://httpd.apache.org/docs-2.0/content-negotiation.html</font</a>>
>
> But I did not get it. I do have a .htaccess file. Can I just put one or
> two lines in there and redirect germans to xx.de?
Content negotiation allows you to create files for different languages
and have the web server automatically choose one based on the user's
language preferences. For example, if you have "Options +MultiViews"
set for a directory, then you could put the following files in that
directory:
index.html.en
index.html.de
If the user's preferred language is English, then Apache would serve
index.html.en; if the preferred language is German, then Apache
would serve index.html.de. If the preferred language is something
else, then the LanguagePriority and ForceLanguagePriority directives
determine what happens: you can have Apache use a default language,
or you can have it ask the user to choose from the available
languages.
Having Apache redirect the user to another web site based on their
language preference involves a little more work. A simple -- but
flawed -- way to do this with mod_rewrite would be:
RewriteEngine on
RewriteCond %{HTTP:Accept-Language} ^de
RewriteRule (.*) <a style='text-decoration: underline;' href="http://xx.de/$1" target="_blank">http://xx.de/$1</a> [R,L]
This method is flawed because it works only if the Accept-Language
header from the user's browser has "de" listed first. Having the
preferred language listed first is common but isn't required, and
the above method doesn't allow for German being acceptable but not
preferred (e.g., the user might prefer Italian but will accept
German if Italian isn't available). See RFC 2616 Section 14.4 for
more information about how the Accept-Language header works:
<a style='text-decoration: underline;' href="http://www.rfc-editor.org/rfc/rfc2616.txt" target="_blank">http://www.rfc-editor.org/rfc/rfc2616.txt</a>
A more reliable way to force a redirect would be to allow content
negotiation to select a file based on the user's language preferences
and have that file issue the redirect. You could use CGI or PHP
to do this, or you could put the following in the <head> section
of an HTML file:
<meta http-equiv=refresh content="0;URL=http://xx.de/">
Note that using http-equiv=refresh is considered bad style by some
people because it can break the browser's "back" button:
<a style='text-decoration: underline;' href="http://www.w3.org/QA/Tips/reback" target="_blank">http://www.w3.org/QA/Tips/reback</a>
Using CGI or PHP to send an HTTP redirect would probably be better.
--
Michael Fuhr
<a style='text-decoration: underline;' href="http://www.fuhr.org/~mfuhr/" target="_blank">http://www.fuhr.org/~mfuhr/</a><!-- ~MESSAGE_AFTER~ -->
>> Stay informed about: redirect german traffic with mod rewrite