Recently we converted a 10 years old Magento single store to a Magento Multi Store. We wanted to add English language (original language was Spanish). We did this by creating a new store, asigning the code /es/ to the Spanish store and /en/ to the English store.

To avoid SEO issues, we had to create some redirection rules:

  • Everything that was on the root path / had to be moved to /es, except for some specific directories (media, admin, etc.)
  • In addition, the website base directory had to be changed from / to /es/

It wasn’t easy to find the final apache configuration that did the trick. In addition, browsers tend to cache redirections and that was annoying: sometimes it worked and we didn’t even know that it did because the browser was still redirecting or not redirecting because of the cache.

Here you have the lines you have to add to your apache server (consider that in this case we consider that /es/ was the language we were keeping as the main one):

# This first line redirects only the root and nothing else
RedirectMatch ^/$ /es/

# These lines redirect from any url which doesn't contain es|en|admin|skin|js|media|import
# or pagespeed to /es/xxxxxx
RewriteCond %{REQUEST_URI} !^/(es|en|admin|skin|js|media|import)/
RewriteCond %{REQUEST_URI} !^(.*)pagespeed(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* /es%{REQUEST_URI} [R=301,NC,L]
Categories: Development


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.