Moving to a modified URL

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I would like to create a link on a web page that will call a script and jump  
to an URL similar but slightly different than the current one.  I am doing  
this to allow people to switch languages.  For example, no matter where the  
user is on my web site, if he clicks on the FRENCH button at the top, he  
will be moved from:


On this French version of the web page, if he clicks on the ENGLISH button,  
he will be moved back to the:

Since we have more than 60 pages, we don't want to create 120 links on each  
page.  We would prefer to have two scripts, one that will insert a /fr after  
the domain name (to move to the French site), and another one that will  
remove this /fr in order to move to the English version of this page.

Is this something that can be done with PHP?

Normand P.  

Re: Moving to a modified URL

Since you seem to have currently all your pages in html, you would
probably have to run through some trouble. First, you'd need to rename
all your files to have a .php extension. Then you should write a PHP
script that creates the French, English, Spanish etc buttons with the
modified URL. And then place a call to said script on top of each page.

You may also be interested in using frames. They are ugly as sin, but
look like a better solution for your particular matter, since you'd
probably only need one php page to show in the top frame, and it would
control the html content of the bottom frame.

Re: Moving to a modified URL

you could do it with a 404 error handler (u need apache) and 2 simple
scripts. one to set a language cookie and the second one to redirect
according to the language cookie.

Re: Moving to a modified URL

this is just pseudo-php code to get an idea of what should be done.

# add the 404 error handling to apache with .htaccess
ErrorDocument 404 /404.php

# setlang.php to create a language cookie
 setcookie("lang", $_GET['lang'], .....)

#the 404 handler
header("Location: /" . $_COOKIE['lang'] . "/" .

to make it work, links must point to a non-existent file.

Re: Moving to a modified URL

With the method I came up with, you don't need to use cookies.  If you
have already made your site, you do not need to change all of the pages
to *.php.  You will need to change the links on all the pages, however,
which would be the case whether you change the file types or not.  Do
something like this.  If you have an index.htm or index.html page,
rename it to home.htm or home.html.  Create an index.php file to put in
your www root.  On the index.php have this code

$translations["en"] = ""; // default
$translations["fr"] = "fr";  // french
// $translations["language abbr"] = "language folder";

// check that variable exists in url
   $lang = $_GET['lang'];
   $lang = $translations["en"];
ini_set("include_path", "/path/to/www/root/".$lang."/");
// change path to your path
   $id = $_GET['id'];
   $id = "error.html";
// create an error page for each lang or set $id to homepage of lang
include($id);  // change ext to your file extention

use <base href=" "> on each page.  For the french
link on each page in the english section, use
<a href="index.php?id=apage.html&lang=fr">
for the english link on each page in the french section, use
<a href="index.php?id=apage">

Site Timeline