• Hello All,

    I created various subfolders of my main website, each subfolder depicts a language code. e.g., www.abc.com/it/ for italian,www.abc.com/es/ for spanish and so on.

    I have created these websites separately with different WordPress installations but all are on the same server.

    Language switcher menu has already been added on the websites. But I want the websites to have auto-redirection to the language specific website based on the language of the browser.

    I know this can be done easily using some multilingual plugins (like WPML plugin) but please note that I have not created these multilingual websites using any plugin. These websites are different subfolders on the server. Also, I have not created a multisite network.

    Considering all of the above information, please let me know what would be the best way to achieve auto-redirection based on the browser language.
    Is there a specific plugin that can help in this? Or, should I modify the .htaccess file? If yes, what code should be added to .htaccess file?

    Look forward to the support from you all valuable WordPress users and experts.

    Thank you in advance.
    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Thread Starter kryptojdubai

    (@kryptojdubai)

    You mean the below htaccess rules:

    RewriteRule ^en/ - [L]
    RewriteRule ^de/ - [L]
    
    RewriteCond %{HTTP:Accept-Language} ^de [NC]
    RewriteRule ^ /de%{REQUEST_URI} [L]
    
    RewriteCond %{HTTP:Accept-Language} ^en [NC]
    RewriteRule ^ /en%{REQUEST_URI} [L]

    Just curious, how does it work, have you tested these by any chance?
    Also – These different multilingual websites will their own .htaccess files, in which of the .htaccess files is the above code to be written?

    Thanks!

    • This reply was modified 5 years, 8 months ago by kryptojdubai.
    • This reply was modified 5 years, 8 months ago by kryptojdubai.
    Moderator bcworkz

    (@bcworkz)

    You you add the rules to the one .htaccess in public root, the folder common to the various language folders. The rules act sort of like a switchboard, channeling requests to the appropriate language folder. I have not tested these, but they appear to do what I had thought of when I first read your question.

    The first two rules prevent the other rules from being used when a specific language has already been requested. When browsers send requests to your server, they send a header that tells servers their preferred language. The %{HTTP:Accept-Language} variable is assigned whatever value the browser sent. The second pair of rules rewrites the request to the /de/ folder when the preferred language code begins with “de”.

    Same goes for the last pair when the preferred language code begins with “en”. “en-US”, “en-GB”, “en”, etc. all will match the ^en parameter.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Multilingual Websites Auto Redirection to Broswer Language’ is closed to new replies.