drupal multisite htaccess: rewrite all languages to default language on one subsite


#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]

If this rule

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

is in your .htaccess file, I am surprised that it works as the leading / is always stripped out, so it should theoretically never match any request.

If your desire is to force a default language of NL for those requests that do not specify a language, then add the following rules to the top of your .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]

If you do not want to redirect, just drop the R=301

I edited code above to replace /fr/some-title with /nl/some-title/. The L flag tells mod_rewrite to stop processing further rules, which is usually what you want, unless you have another rule that needs to further process the current request.

Tags: Regex / Apache / Drupal

Similar questions

.htaccess rewrite base URL up one directory level
I have an established Drupal installation at example.com/drupal - and now I need to move the installation up one level to the domain root. So the rewrite rule I need is to redirect all existing URLs - e.g. example.com/drupal/some_section/somepage to example.com/some_section/somepage etc. How do I do this?
.htaccess referrer rewrite rule for one pretty url
I need to ensure that the user login form for Drupal can not be signed into when the referrer is from a remote domain. It is a security vulnerability which impacts enterprise acceptance. The path is: https://domain.com/user There is currently a rule in place at the end of .htaccess to require https access I looked at this to see how the rule might ...
Disable language prefix for non-default languages
I'm migrating a plain multilanguage HTML site to Drupal 7. One of the requirements of the migration is to preserve the current URLs of each page. Right now, the site has three languages and has URLs like these: www.example.com/files/content1/es.html www.example.com/files/content1/en.html I've Internationalization and Pathauto modules enabled, and s...
How do I create a view with mixed languages, showing the node's original language by default?
I have a site with mixed languages, Spanish and English. Some content was originally created in English, then translated into Spanish. Other content was originally created in Spanish, then translated into English. The remaining content is either in Spanish or English and is not translated. How do I create a view that shows all of this content in th...
How do I redirect users from Japan to a certain subsite?
I want users from Japan to be redirected to www.example.com/test2 when they hit www.example.com/test1. In the menu only Test1 is visible. What tools do I need? I tried to insert a PHP script into the header with the 'Add to Header' module, but for that I need the directory of the sites, which I do not have. I can also set Geo Rules, but then I have...
It does not work when installed as "subsite"
I tried to install Drupal 8.03 on a windows 7 64 bit server, with MySQL, Apache and PHP 7.03, using the default install procedure / script. Drupal is only one of the applications on the website and that is probably different from what Drupal 8 seems to expect. The website is like https:/www.mysite.nl and overall root folder is x:\myroot\homepage. D...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.