Redirection based on language

I have two web sites under this domain, the one in Turkish is located at /tr and the one in English is located at /en path. These are separated WordPress installations, not in a network. I had to make a choice for my visitors reaching directly to my domain root. Welcoming them with a static language choice page was an option, but this was not a good idea in my opinion.

I have searched for some time to find an answer to this question: How could I seamlessly and automatically redirect my visitors to my WordPress sites located on my domain’s subfolders based on their preferred language, by avoiding explicitly forcing them to choose a language when they reach my domain?

I will shortly explain here how I have successfully set this configuration up with just two files.

I use this index.php file at / (root):

And this .htaccess file at / (root):

By using those two files and locating my web sites in their respective subfolders, my visitors accessing directly to “” are silently being redirected to Turkish or English sites on this domain based on their language choices in their browsers (Firefox users may choose their preferred language in Preferences/Content/Language section, for example).

A little complicated scenario

You may use the configuration above as it is if you set new web sites up. My case was a little complicated. At first I had only my site in Turkish on my domain and it had been accessible for a long time. Therefore search engines had already indexed that web site with its address structure. I then moved this installation to “/tr” subfolder and created a new site in “/en” subfolder.

To keep existing links from third party sources such as search engines directly to my domain root (in other words, for backward compatibility), I used a different “.htaccess” file at / (root) path.

Modifying .htaccess file can be a complicated task for those who do not have enough experience. These codes are often used as they found around the web.

There is also a tendency to treat rewrite rules as magic incantation, using them without actually understanding what they do. (from Official Apache Documentation)

Making modifications according to my need could only be possible by understanding the code with the help of the documentation. If you do not have that time or interest you may take a quick look at this page.

This “.htaccess” file redirects all files and directories which are not accessible on root to /tr.

The block above provides this result.

For example, a request to “” will be redirected to “”, as there is not any “2016” directory at root.

Changing “Site address” and “WordPress address” fields of “Admin/General” tab on the dashboard of my Turkish wordpress site as “” was also necessary.

Now both sites and automatic redirection perfectly work.

4 thoughts on “Redirection based on language

  1. Any problems with loading speed of the website with this?

    I have a redirect.php for WPML and it looks like my script needs over 2 seconds “more” to forward and loading the full website!


  2. Just attach the landing page of your respective WP installation as a link to the language button. For example, check target links of flag icons on this site at the upper-right corner.

Leave a Reply

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