• I've got a Drupal 6 multisite, with 2 domain names (www.example.com and www.domain.com), discussing some common content.

  • The domain example.com is within three languages (EN, FR, NL). Languages are positioned by path prefix (/en, /fr, /nl). Another domain domain.com is simply in a single language (NL).

  • The issue: on many occasions domain.com is proven within the wrong language, even when no path prefix is completed. In some way it appears to default to EN, although it does not always do this - behavior does not appear to be really consistent.

  • The answer (a minimum of I really hope): since I am not really a Drupal developer (I inhereted the website from the former friend) I've no clue how you can fix this in Drupal, and so i thought the easiest method to fix it might be to include some rewrite rules to .htaccess.

  • I am no htaccess/regex expert either, and should not have it working. You'll find my current rewrite rules below, any help or suggestions are most welcome.

  • Some good examples:

    • www.domain.com/fr/some-title must be rewritten to www.domain.com/nl/some-title
    • www.domain.com/node/1975 must be rewritten to www.domain.com/nl/node/1975

Fundamental essentials rewrite rules which were already there:

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

I attempted adding this:

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteRule ^/(.*)$ /nl/$1

and would expect this simply to prepend /nl/ to any or all pathways (thus not a complete solution since /fr/some-title would become /nl/fr/some-title) - however, a fast test shows me that:

  • /fr/some-title is rewritten to /nl/some-title (that is things i need, although not things i expected)
  • /some-title isn't rewritten

  • The question: any ideas what may be wrong? Or could this be triggered by other (Drupal) configurations? Or it is possible to better method to solve my problem?

  • Just with regard to completeness: the live website is www.cinemazuid.be

If the rule

RewriteRule ^/(.*)$ /nl/$1

is within your .htaccess file, I'm surprised it works because the leading / is definitely removed out, therefore it should theoretically never match any request.

In case your desire would be to pressure a default language of NL for individuals demands that don't specify a language, adding the next rules to the peak of the .htaccess file, before any existing rules

#if request is for existing file or directory
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
#then stop processing
RewriteRule .* - [L]

#replace fr with nl. This rule
RewriteRule ^fr/(.*)$ /nl/$1 [L,R=301]

#if the request does not have a language of en or nl
RewriteCond %{REQUEST_URI} !^/(en|nl)/ [NC]
#redirect with nl as default language
RewriteRule .+ /nl%{REQUEST_URI} [L,R=301]

Should you don't want to redirect, just drop the R=301

I edited code above to exchange /fr/some-title with /nl/some-title/. The L flag informs mod_rewrite to prevent processing further rules, that is usually what you would like, unless of course you've another rule that must further process the present request.

#redirect /fr/* and /en/* to /*
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(en|fr)/(.*)$ /$2 [R,L]

#internally rewrite /* to /nl/*
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond $1 !^nl/$ [NC]
RewriteRule ^(.*)$ /nl/$1

#drupal code
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]