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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:48:55+00:00 2026-06-15T06:48:55+00:00

I have a WordPress site in two languages (Hebrew and English) and I need

  • 0

I have a WordPress site in two languages (Hebrew and English) and I need it to redirect according to browser language. I’m using qTranslate plugin to create the content in both languages. This plugin also has a redirection functionality but it creates a redirection only for the homepage and I need the redirection to happen for internal pages as well as the homepage.

Another developer wrote this code for me to create the redirection, but for some reason it creates a funny redirect. It happens only when switching language to Hebrew, then leaving the site and trying to enter directly to http://domain.com/en/ and it redirects you to http://domain.com/domain.com/ (Does not happen when switching to english).

I tried playing with the “header (Location: )” that creates the redirection for Hebrew, but couldn’t figure out how to make it work – I tried using the full path instead of relative path, or removing the “/” between $_SERVER['SERVER_NAME'] and $_SERVER['REQUEST_URI'] but got recursive url or url with double “/” (http://domain.com// and also for internal pages http://domain.com//page).

The url structure is:

  • domain.com/ for Hebrew
  • domain.com/en/ for English

and when switching language then the parameter $lang=en or $lang=he is being added.

Hope this makes sense, and thanks a lot!

this is the code that is responsible for the redirection:

<?php
if (!isset($_COOKIE["uln"])) : 
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
setcookie('uln', $lang, time()+86400*365, '/', '.domain.com'); // cookie stored for a year
$_COOKIE['uln'] = $lang;
endif;

//if lang=(value) is not empty 

if(isset($_GET['lang'])) {
$lang = $_GET['lang'];

 setcookie('uln', $lang, time()-1, '/', '.domain.com');  //this unsets the cookie for random language selection

 //set the cookie "uln" again with the selected language.
 setcookie('uln', $lang, time()+86400*365, '/', '.domain.com'); // cookie stored for a year 
 $_COOKIE['uln'] = $lang;
}



        if(($_COOKIE["uln"]) == "en") {
        $matched = strncmp("/en/", $_SERVER['REDIRECT_URL'], 3);                               
        if ($matched !== 0) :       
        header('Location: /en'.$_SERVER['REQUEST_URI']);        
        endif;
   } elseif(($_COOKIE["uln"]) == "he") {
        $matched = strncmp("/en/", $_SERVER['REDIRECT_URL'], 3);                               
        if ($matched === 0) :       
        header('Location: '.$_SERVER['SERVER_NAME'].'/'.$_SERVER['REQUEST_URI']);       
        endif;
   } 

 ?>  
  • 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-06-15T06:48:56+00:00Added an answer on June 15, 2026 at 6:48 am

    instead of

     header('Location: '.$_SERVER['SERVER_NAME'].'/'.$_SERVER['REQUEST_URI']);       
    

    try

     header("Location: http://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}");   
    

    URLs, especially those in Location headers, should include a protocol and domain name. I believe relative URLs in Location headers are a violation of the HTTP RFCs.

    By omitting a protocol, you’re unintentionally specifying a relative url instead of an absolute one.

    Edit: REQUEST_URI is already prefixed with a / so including one in the concat is unnecessary.

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

Sidebar

Related Questions

I have two similar wordpress websites. http://site.com/ and http://site.com/en/ When I try to load
I've installed a plugin for Wordpress Titled CMS Press onto my Site. I have
I have a Wordpress site that uses two databases -- one section queries one
I have a wordpress site with jQueryUI tabs applied to two different elements of
I have develop a site using wordpress. Its running fine on local machine (windows
I am trying to post to my wordpress site by xml-rpc. I have two
I have a wordpress site, and a plugin uses cufon text replacement. (I'm not
I have a wordpress site that I am using a child theme with. In
I have looked around the WordPress plugin site for some time and so far,
I have wordpress a site with a customized login page, the problem is when

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.