Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1061403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:28:08+00:00 2026-05-16T18:28:08+00:00

A few weeks ago i asked a question about a multilanguage site (see Multilanguage

  • 0

A few weeks ago i asked a question about a multilanguage site (see Multilanguage site, subdirectories as language (RewriteRule)).

That works perfect (thanks for that)
But since I want to make my website nicer and I started adding more languages a new problem showed up.
I want to see if I can redirect users directly to the site in their language, if this language does not exists or a cookie is set I want to redirect users to their last language or my default language.

For now I created this part in my .htaccess

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?$ en/ [L,R=301]

This causes that all calls to http://www.xxx.com/ are redirected to http://www.xxx.com/en/

Now the second part, in my php code I store a cookie this cookie is set for http://www.xxx.com/

I tried the following:

RewriteCond %{HTTP_COOKIE} language=([^;]+) [NC]

RewriteRule ^/?$ %1/ [L,R=302]

But this gives me an infinite loop.

I also tried this, so if my language is nl redirect to http://www.xxx.com/nl/ but this also results in an infinite loop. Also this code should only be executed in some cases

RewriteCond %{HTTP:Accept-Language} (nl) [NC]
RewriteRule ^/?$ nl/ [L,R=302]

Can someone help me and is this possible in an htaccess or should I create some logic in PHP?

1 Check if cookie is set with a language ( I guess this should be the above stated code)
 2a If a cookie is set redirect the user to that language
 2b If no cookie is set check the http-accept language
  2b1 If this language exists redirect to that language
  2b2 If that language does not exists redirect to the default

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:28:08+00:00Added an answer on May 16, 2026 at 6:28 pm

    Accept-Language is a list of weighted language identifiers. Just the occurrence of a certain language identifier does not mean that it’s the most preferred language. There might be other languages that are more preferred (higher q value) or even not accepted at all (i.e. q=0).

    So instead of just looking for a certain language identifier, parse the list of accepted languages and find the best match of accepted languages and available languages while considering the preference order. And since you seem to be using PHP, do that with PHP instead of mod_rewrite.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was asked a few weeks ago, to find all the different and unique
I started using symfony a few weeks ago, and there are some things that
Im added few weeks ago a like button and comments to my website and
I've been studying Prolog for a few weeks ago and something trivial I keep
I'm new to Qt as of a few weeks ago. I'm trying to rewrite
I have created a mobile version of a site. It uses the CodeIgniter session
I'm helping with a rather ad-hoc disaster recovery, and we've restored a database backup
Hey guys... Its quite late in the night right now and I'm taking some
I ran into a strange issue - iAd Tester app is no longer present
We are getting a large number of SQLiteDiskIOException errors in our Android app, with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.