
Originally Posted by
lhungil
Nice. Please consider contributing your changes! If you send them my way (PM or EMAIL) I will look over them further and consider them for inclusion in a future version

I can't guarantee compatibility with other settings and plugins though, but it mainly involves adding this to .htaccess before the start of the Ultimate SEO rewrite rules:
PHP Code:
RewriteRule ^(en|nl)/(.*)$ $2?language=$1 [QSA,L]
and in functions/html_output.php change:
PHP Code:
$href_link = $seo_urls->href_link($page, $parameters, $connection, $add_session_id, $static, $use_dir_ws_catalog);
to
PHP Code:
// adds the current language as a directory to all links,
if (isset($_SESSION['languages_code'])){
$language_tag_content=$_SESSION['languages_code'];
}else{
// if no $_SESSION['languages_code'] parameter is found, the default language is added to all links:
$language_tag_content=DEFAULT_LANGUAGE;
}
// give preference over language code in the language variable
// the language GET variable is extracted and removed in case a language parameter is present in the url
// (which is the normal case since .htaccess converts the language directory into a language GET variable):
if (strstr($parameters,'language=')){
$language_pos = strrpos ( $parameters , 'language=');
$language_code_pos = $language_pos + 9;
$language_tag_content = substr ( $parameters , $language_code_pos ,2 );
// remove language tag from parameters:
$parameters = substr ( $parameters , 0 , $language_pos) . substr ( $parameters , $language_pos+11);
}
// generate the link without language parameter:
$href_link = $seo_urls->href_link($page, $parameters, $connection, $add_session_id, $static, $use_dir_ws_catalog);
if($href_link === null) {
$href_link = original_zen_href_link($page, $parameters, $connection, $add_session_id, $search_engine_safe, $static, $use_dir_ws_catalog);
$href_link = str_replace('%20','+',$href_link);
$href_link = str_replace('&','&',$href_link);
}
// include the language tag content as a directory in the link url. htaccess will convert this into a regular language GET variable
if (strstr($href_link,HTTPS_SERVER.DIR_WS_HTTPS_CATALOG)){
$href_link = HTTPS_SERVER.DIR_WS_HTTPS_CATALOG . $language_tag_content .'/'. substr ( $href_link , strlen(HTTPS_SERVER.DIR_WS_HTTPS_CATALOG));
}else{
if (strstr($href_link,HTTP_SERVER.DIR_WS_CATALOG)){
$href_link = HTTP_SERVER.DIR_WS_CATALOG . $language_tag_content .'/'. substr ( $href_link , strlen(HTTP_SERVER.DIR_WS_CATALOG) );
}
}
If you turn off "automatic redirects", you can use something like the following:
Code:
$tmp_lng = new language();
foreach($tmp_lng->catalog_languages as $lng) {
// Initialize a new generator for a specific language (by language_id).
${'usu_' . $lng['code']} = new SEO_URL($lng['id']);
// Create a link using the generator for a specific language (make sure to define $excludeParams).
${'link_' . $lng['code']} = ${'usu_' . $lng['code']}->href_link($current_page, zen_get_all_get_params($excludeParams), $request_type, false);
// Alternate available for the specified language.
if(${'link_' . $lng['code']} !== null) {
// Do something with the link (such as add an alternate).
}
unset(${'usu_' . $lng['code']}, ${'link_' . $lng['code']});
}
unset($tml_lng, $lng);
Your suggestion was sort of what I tried already and doesn't work.
But I found out that the problem was caused by the cache. If I turn off the seo url cache it works!
And also it was helpful to use this way of looping through the languages in order to find the id and the language code together.
I changed my mind about the default language page btw. I use it also for the social media buttons, to combine the like/share counts for all languages. I thought it would be a good idea to have a very short url, so it leaves more room in tweets. However, on second thought I have now chosen to use a slightly shortened version of the English url for the x-default language page and the social media tweets/shares/likes (regardless of the chosen language):
HTML Code:
<link rel="canonical" href="http://art.horisense.com/nl/canvas-c-8/canvas-40x30-pastel-papaverdanseres-p-31.html" />
<link rel="alternate" href="http://art.horisense.com/canvas-c-8/canvas-40x30-pastel-poppy-dancer-p-31/" hreflang="x-default" />
<link rel="alternate" href="http://art.horisense.com/nl/canvas-c-8/canvas-40x30-pastel-papaverdanseres-p-31.html" hreflang="nl" />
<link rel="alternate" href="http://art.horisense.com/en/canvas-c-8/canvas-40x30-pastel-poppy-dancer-p-31.html" hreflang="en" />
In this way, I may still at least benefit from the english keywords in the url, when my product url's are shared in tweets.
Bookmarks