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 6932919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:45:58+00:00 2026-05-27T11:45:58+00:00

I have successfully set up localisation on my website using php gettext, and a

  • 0

I have successfully set up localisation on my website using php gettext, and a browser cookie is set when a visitor chooses their preferred language.

Whilst the pages are shown in the correct language, I want the URL to reflect the currently selected language by prefixing the URL with the language code (not the locale code).

This is what my htaccess file looks like at the moment:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^en(/?$|/(.*)) $1?locale=en_GB [QSA,DPI,L]
RewriteRule ^fr(/?$|/(.*)) $1?locale=fr_FR [QSA,DPI,L]
RewriteRule ^de(/?$|/(.*)) $1?locale=de_DE [QSA,DPI,L]
RewriteRule ^es(/?$|/(.*)) $1?locale=es_ES [QSA,DPI,L]
RewriteRule ^ru(/?$|/(.*)) $1?locale=ru_RU [QSA,DPI,L]

Let’s say a visitor clicks on the French language link on the homepage, the URL displayed to the visitor is mysite.com/fr and the language changes to French.

If they then click on the link for page1.php the URL changes to mysite.com/page1.php and the French version of Page 1 is displayed.

I would like the URL to be shown as mysite.com/fr/page1.php.

I’ve tried adding the following lines to htaccess, just below the RewriteCond lines, but I’m clearly doing it wrong:

RewriteCond %{HTTP_COOKIE} locale=([a-z]{2}\_[A-Z]{2}) [NC]
RewriteRule ^(.*)$ /%1/$1 [NC,L,QSA]

Note that in the lines above, I am attempting to prefix the URL with the entire locale code (e.g. fr_FR) whereas ultimately what I want is to prefix the URL with just the first two characters of the locale code (e.g. fr).

Thank you 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-27T11:45:59+00:00Added an answer on May 27, 2026 at 11:45 am

    I don’t think you should use .htaccess rewrites for this ..

    1. If a user comes to your site with the URL:

    http://mysite.com/page1.php you should figure you what language you want to show to him and redirect him, for instance to: http://mysite.com/en/page1.php – by looking at the browser language accept value for instance.

    1. If a user comes to your site with a URL like:

    http://mysite.com/en/page1.php then you don’t have to do anything, you know which language to use.

    I can strongly recommend you don’t use cookies for this. Many sites use cookies for this for absolutely no purpose at all, all they do is send you to the page in whatever language you selected. Completely infuriating if you don’t accept cookies by default (which everyone should).

    Keep in mind that all your links on your site will always have the language as part of their URL, because if they don’t you’re back to situation 1 and your user might get switched back to the default language. Using a cookie here will only complicate matters, what if you really did want to switch to the French site after using the English site for a bit?

    I guess the bottom line is: don’t use cookies in combination with your URL to identify a resource, it becomes very vague which resource exactly you’re referring to because cookies are not obvious. The only exception is of course when you’re doing some authentication stuff like user accounts and whatnot, but then lack of a cookie should always result in a ‘please log in’, not something that looks like the thing you wanted, but isn’t.

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

Sidebar

Related Questions

I have successfully implemented this method of using the Win32 API to set the
I am using the scripts from here http://www.quirksmode.org/js/cookies.html and have successfully created a cookie..
I have a CGI script for which I've successfully set a cookie (which I
I have successfully implemented a multi-language website in which user can change language by
I am using open source C++ library DCMTK from http://dicom.offis.de/dcmtk.php.en . I have successfully
We have successfully set up a couple of local package repositories using the NuGet.Server
I am using a DialogFragment , and while I have successfully set an image
I have set an event successfully using myEntry.setTitle(new PlainTextConstruct(TEST)) myEntry.setContent(new PlainTextConstruct(See how much text
I have successfully set up FILESTREAM on my SQL 2008 server; however I've noticed
I have successfully set up an HgWebDir instance over CGI with Apache, and I

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.