0

I want to get the language prefix from url with Wordpress, but I don't know how. if I have the following url http://sitename.com/ru/about-us, I want to get the full path including /ru/, but whatever I try i don't get it ,e.g

$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']

I am using qTranslate plugin, and my site it multilanguage

I just want to check if the url link has language prefix after host name, I can do that if i get the whole url, but I can't get it, anybody can help me?

Anna Gabrielyan
  • 2,120
  • 3
  • 28
  • 48
  • Is this single or multisite installation? – Minister Jan 23 '14 at 06:41
  • it is mulitlanguage site, using qtranslate – Anna Gabrielyan Jan 23 '14 at 06:43
  • 1
    run `echo var_dump($_SERVER);` and look at result. maybe helps. – marioosh Jan 23 '14 at 06:46
  • REDIRECT_URL, that is what i need, thanks @marioosh – Anna Gabrielyan Jan 23 '14 at 06:53
  • @anulik It would be good to include the fact that it's a single site installation and multilanguage using qTranslate in your question (even if it is already resolved)! :-) – Minister Jan 23 '14 at 06:53
  • ok, just added, thanks for note – Anna Gabrielyan Jan 23 '14 at 06:56
  • I'm not sure $_SERVER['REDIRECT_URL'] will work for you to fix the multilang issues - http://stackoverflow.com/questions/6483912/php-serverredirect-url-vs-serverrequest-uri What you tried to get the requested URI is the correct way! Let me know the results if you try the plugin I posted in my answer... – Minister Jan 23 '14 at 07:20
  • @Minister, i don't need to make any changes to my .htaccess, my main point is, i have 3 sites with different domeins, site.am, site.ru, site.com,wich are working with single db, and in db sTranslate has set as default language english, if i open site.ru my site default language must be russian, so my site language at first for site.ru must be russian – Anna Gabrielyan Jan 23 '14 at 07:52
  • so in my functions.php i am just getting the /ru/ or /en/ from my url, and if that prefixs are not exists i am changing language, if not just letting to qTranslate do his work $q_config['default_language'] = $current_domain_lang; $url = substr($_SERVER['REDIRECT_URL'],0,4); if($url!="/en/" && $url!="/am/" && $url!="/ru/"){ $q_config['language'] = $current_domain_lang; $q_config['default_language'] = $current_domain_lang; } – Anna Gabrielyan Jan 23 '14 at 07:54
  • it is working for me, i just get what i need – Anna Gabrielyan Jan 23 '14 at 07:54
  • the point is i have tried to use $_SERVER['REQUEST_URI'], but i don't get the language prefix, it returns just /about-us/, but the $_SERVER['REDIRECT_URL'] is including the lang prefix, /ru/about-us/, see above, i have wrote in my question, that i had tried the $_SERVER['REQUEST_URI'] – Anna Gabrielyan Jan 23 '14 at 08:00
  • OK, I'm not going to change your mind... Just cheched my WP+MU and [REDIRECT_URL] => /ru/contact/, and also: [REQUEST_URI] => /ru/contact/ (If some day it doesn't work as you may need, keep that in mind. It could be better to check your server config some day...) – Minister Jan 23 '14 at 08:16

2 Answers2

0

This question seems similar to another one. The fix could be to install the following plugin:

http://wordpress.org/plugins/qtranslate-slug/

It should fix the URL problems that as it seems qTranslate has.

Reference: Keep the string prepended in request uri

If not working, you may want to try all other suggested code...

Community
  • 1
  • 1
Minister
  • 1,198
  • 2
  • 10
  • 18
-1

You can easily do that with Permalinks option from your WP dash board. Go to Settings > Permalinks. Select Custom Structure and add this line /ru/%postname%/.

DasCodes
  • 334
  • 1
  • 4
  • 15