Jump to content

How to make URL Redirections from one PHP Page to another webpage?


izy

Recommended Posts

Hy!

Subject: How to make URL Redirections from one PHP Page / site to another webpage in same website or different in PHP?

 

I have PHP multilanguage webpage and I have all content of pages translated into english and german language.

 

Problem:

 

I'm watching content of page in english language(on that link:

/index.php?page=out&id=509&lang=en)

 

On second step I want to see the same content of  page which I saw before in german language(/index.php?page=out&id=509&lang=de

).

Problem is that my code/webpage always links you to first page of langauge(index) which we choose.

 

Please give me an example how to fix it up. Thanks in advance

 

i.

So you mean if you are currently watching

 

index.php?page=out&id=509&lang=de

 

and you on that page change the language to english you get redirected to

 

index.php?lang=en

 

so your site "forgets" which page you were watching when you change language?

 

If that is your problem then the following could be a solution. When you create the link which your language select box redirects to use the following method:

 

<?PHP

$request_query = "page=out&id=509&lang=de";

function create_language_link($language){
  $request_query = "page=out&id=509&lang=de";
  $request_query = preg_replace("/&lang=(en|de)/","",$request_query);

  $link = "index.php" . "?" . $request_query . "&lang=" . $language;

  return $link;
}

?>

 

This takes the query string which index.php was requested with and removes any language queries. Then it puts it together with "index.php?" and a new language query specified in by $language in the function call. So the following will create a link for your language select box and remember where you were:

 

echo create_language_link("de");

 

Wuhtzu

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.