Forum Moderators: phranque

Message Too Old, No Replies

Multilingual France-based website

I need help writing the .htaccess rules for a French, multilingual website.

         

w3bmastine

10:35 am on Feb 4, 2016 (gmt 0)

10+ Year Member



Hi everyone,

I am kind of experimenting right now and am currently trying to set up a mulilingual (single region) website. I definitly need some help with my settings here...

Let's assume example.com is my website in English. Now I want to split it up in French and English, with the location France. (I just add the location in case I will add more locations later that year.) Want I want to achieve:

en-fr.example.com = English version of french website
fr-fr.example.com = French version of french website

Requests to example.com should be checked for language preferences and their location. If the request comes from France, and/or the language preferences are French I want the request to be redirected to fr-fr.example.com. All other requests shall be redirected to the english website en-fr.example.com.

I know I can probe for browser languages (French and Breton in this case) and redirect like that

RewriteEngine on
RewriteCond %{HTTP:Accept-Language} (br|fr) [NC]
RewriteRule .* fr-fr.example.com [L]


  • How would a redirect based on country IP ranges look like (I assume similar to a country IP range block) and
  • How should I begin to mix this with my other settings (rewrites) so far?


This is what I used to develop the french version:


Options +FollowSymLinks +Multiviews
RewriteEngine on
RewriteBase /

AddCharset UTF-8 .html

# enforce trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^!/$ http://fr-fr.example.com/$1/ [R=301,L]

# index.html rewrite
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://fr-fr.example.com/$1 [R=301,L]

# extensionless url's
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.]+\.html?[^\ ]*\ HTTP/ [NC]
RewriteRule ^(([^/]+/)*[^.]+)\.html$ http://fr-fr.example.com/$1? [NC,R=301,L]


I assume you agree that this is a nice mess I'm trying to cleanup. I am a beginner in this topic and am in hope for some help / guidance here. Thanks in advance for your help!

not2easy

2:25 pm on Feb 4, 2016 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Sorry, this doesn't really answer your question, but asks another. Why not just offer visitors the choice with a language button? I personally dislike getting pushed to the wrong version of a website with no way to see the version I want to visit because of the carrier or device I am using.

w3bmastine

7:05 pm on Feb 4, 2016 (gmt 0)

10+ Year Member



Your question is welcome. The button is already implemented. BUT I need to decide where to send people when they enter just example.com or www.example.com. For me it's also an OK solution to push them to the en-fr.example.com (kind of international) website. But I need to push them somewhere.

lucy24

9:50 pm on Feb 4, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I agree with not2easy. Don't redirect at all, unless the user has already expressed a preference. If they request example.com, give them example.com.

For your "default" language, pick the one that real-life users are most likely to choose, whether English or French. That is: it shouldn't be en.example.com vs. fr.example.com vs. br.example.com vs eu.example.com vs etcetera; let it be example.com vs all the other stuff. Years from now, when your site exists in seventeen languages and you are as big as wikipedia, then maybe you can start with a "pick your language" page.

w3bmastine

8:49 am on Feb 5, 2016 (gmt 0)

10+ Year Member



Thanks for your reply. I get your point. After getting some sleep I am even of the opinion that I should only target languages not language and country.

However, I believe it is a good idea to have en.example.com and fr.example.com and to redirect requests to example.com to en.example.com (what real-life users are most likely to choose). I like that better than having just example.com and fr.example.com.

Also, I look at URLs (and domain names in this case) as a user interface so, in my eyes, it seems more user-friendly (because consistent) to communicate all the languages in the URL. Thus English should be in there as well. The question is, how do I achieve that with my current settings?

Thanks for your advices so far.