Hello David :)
I want to append a ?lang=$language_code on all the .php pages and directories of the website and I would like to rewrite it like this:
site.com/language => index.php?lang=language
site.com/language/merchant/ => search.php?q=merchant:Merchant&lang=language
site.com/language/product/ => products.php?q=Product+name&lang=language
site.com/language/category/ => search.php?q=category:Electronics:&page=2&lang=language
etc...
My htaccess is like this:
Options -MultiViews
RewriteEngine On
RewriteBase /pt/
RewriteRule ^product/(.*).html$ products.php?q=$1&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^review/(.*).html$ reviews.php?q=$1&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^merchant/$ merchants.php
RewriteRule ^merchant/(.*)/$ search.php?q=merchant:$1:&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^merchant/(.*)/(.*).html$ search.php?q=merchant:$1:&page=$2&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^category/$ categories.php
RewriteRule ^category/(.*)/$ search.php?q=category:$1:&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^category/(.*)/(.*).html$ search.php?q=category:$1:&page=$2&rewrite=1&%{QUERY_STRING} [L]
I've tried different ways and I'm beginning to doubt if it is actually possible to do this.
David, can you help me with this?
That is a very good idea but what would I put on the subfolders associated with the subdomains? Example fr.website.com would be website.com/fr and that folder would be empty.
Hi,
The method above wouldn't require any sub-directories - you just have the one Price Tapestry installation at http://www.example.com/ and then it simply picks which $translate array to use based on $_SERVER["HTTP_HOST"], so if you set-up http://fr.example.com/ as an alias (in other words it points to exactly the same folder on your webserver) that's all there is to it!
Cheers,
David.
--
PriceTapestry.com
Hello,
I am trying to use this mod, to create different language translations based on subdomains.
Could you please give an advice were tu put this code "switch..."? Should it go at the end or at the begginig? Maybe other modding is requried as written in topic by author?
I can't get it working...
Thanks,
Karolis
Hello Karolis,
The code needs to go into includes/translate.php
However the distribution version does not contain any translations so that may be why it is not clear exactly where the code goes. A complete version of includes/translate.php in which you can add any string translations as required per sub-domain would be as follows:
<?php
switch($_SERVER["HTTP_HOST"])
{
case "fr.example.com": // French
$translate["Best Price"] = "Meilleur Prix";
$translate["Search"] = "Recherche";
// etc. etc.
break;
case "es.example.com": // Spanish
$translate["Best Price"] = "Mejor Precio";
$translate["Search"] = "Buscar";
// etc. etc.
break;
}
function translate($text)
{
global $translate;
return (isset($translate[$text])?$translate[$text]:$text);
}
?>
Hope this helps;
Cheers,
David.
--
PriceTapestry.com
Hi,
Are you set on needing to use www.example.com/language/?
A potentially much easier to set-up method would be to create sub-domain aliases of the site for each language, e.g.
www.example.com (for English language site)
fr.example.com (for French version)
es.example.com (for Spanish version)
etc. etc.
Then, it is a simply case of using a switch statement looking at $_SERVER["HTTP_HOST"] in includes/translate.php to decide which $translate array to use! For example;
switch($_SERVER["HTTP_HOST"])
{
case "fr.example.com": // French
$translate["Best Price"] = "Meilleur Prix";
$translate["Search"] = "Recherche";
// etc. etc.
break;
case "es.example.com": // Spanish
$translate["Best Price"] = "Mejor Precio";
$translate["Search"] = "Buscar";
// etc. etc.
break;
}
Hope this helps!
Cheers,
David.
--
PriceTapestry.com