I have a multilanguage website. The main language is English and the second language is Spanish.

I need to have all the traffic using this domains:

  • English domain: www.example.com
  • Spanish domain: es.example.com

If I use the .htaccess rules from Drupal, I can redirect all the traffic to www, but it includes the Spanish traffic too. Or I can remove www to use es.example.com, but again, it would redirect the English traffic to use example.com (without www).

I have tried a lot of .htaccess combinations but I finish in a worst situation that is redirecting the Spanish traffic to the Encglish URL, so... I need to know what rules can I use to have these redirections:

  • example.com to www.example.com
  • www.es.example.com to es.example.com

These rules must be included in Drupal's .htaccess file, before the RewriteBase / line.

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ http%{ENV:protossl}://www.example.com%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^www\.es\.example\.com$ [NC]
RewriteRule ^ http%{ENV:protossl}://es.example.com%{REQUEST_URI} [L,R=301]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.