Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect users based on browser language (not in php) [closed]

My website will be in 3 languages. French (fr) is the default language. The structure of the site is the following:

Root directory (note: I'm not using php files, just plain html)

/fr/
    Index.html
    About-us.html
    Contact.html

/en/
    Index.html
    About-us.html
    Contact.html

/de/
    Index.html
    About-us.html
    Contact.html

I got questions:

  • What is the best practice to redirect users based on their web browser language? Via htaccess?
  • Do I need a index.html page at root level (for SEO reason or any other reason) ? The French index.html perhaps?
like image 462
Greg Avatar asked May 02 '16 15:05

Greg


1 Answers

Super easy tool here:

http://www.htaccesstools.com/redirection-by-language/

Makes life incredibly easy for htaccess redirects based on the browser's language.

Example:

RewriteEngine on
RewriteCond %{HTTP:Accept-Language} (fr) [NC]
RewriteRule .* /fr/index.html [L]
RewriteCond %{HTTP:Accept-Language} (en) [NC]
RewriteRule .* /en/index.html [L]
RewriteCond %{HTTP:Accept-Language} (de) [NC]
RewriteRule .* /de/index.html [L]

This is a hard redirect, the browser's location bar will indeed show the new page. Though, this is better for UX than an internal redirect masking the URL.

To answer your question, it is highly regarded that an index.html provides the best UX. However, that's essentially because people have come to expect this in general (website.com/en/, website.com/fr/, etc.). SEO-wise, no, you wouldn't get dinged if you didn't follow that same structure.

Best practice is to use your best guess (like the htaccess), and still offer a menu for switching languages. Plus, you'll also need a fallback for if the Accept-Language isn't actually defined (like going to /en/ by default). This could be a final line in the htaccess, or it could simply be an index.html at the root level, where .htaccess is.

Other than that, there's not a tremendous amount that goes into localization.

like image 114
Nate I Avatar answered Oct 05 '22 11:10

Nate I