Forum Archive - [Solved] Get current URL via PHP

[Solved] Get current URL via PHP
Jan 5, 2013 10:42 pm by Dawn
Hi, I'm using some php code to get the current active url and the current active uri. I need this to dynamicaly insert a canonical tag. It works great, but I've noticed that when I'm using your extension and access for example /en/ or /ru) it doesn't give me the right url's back. It returns the real url, but not the URL of the translation. Example: url shown in browser: http://www.domain.com/en/content?param1=1 return url: http://www.domain.com/content (and: http://www.domain.com/content?param1=1) which is wrong and should return: http://www.domain.com/en/content (and http://www.domain.com/en/content?param1=1) I use the following code: // Get SEO Page URL $pageUrl = JURI::current(); // Get URI Object $uri = & JFactory::getURI(); // Get URI String $pageUri = $uri->toString(); I can deal with this myself, but can you please tell me how to get the real (SEO) url including your language "subdirectory" (by php - in this two variants)? Would be really important for me. Best regards, Dawn
Re: Get current URL via PHP
Jan 6, 2013 4:05 pm by Edvard
Hi, You can use JSession::get('glang'); to get the current selected language which will help you to generate the current URL.
Re: Get current URL via PHP
Jan 7, 2013 7:03 am by Dawn
Hi Edward, Thanks a lot! I think I can go with this solution. Best regards, Dawn
Re: [Solved]Get current URL via PHP
Jan 9, 2013 8:46 pm by Dawn
Sorry to reopen this thread, perhaps it's a stupid question (Googled around too) but I'm not able to get anything. I've used the following code in my index.php: $test = JSession::get('glang'); echo($test); Do I have to include something before? The other code I posted above works at exactly the same place, without any problems. Would be extremely nice from you if you can tell me how to get current selected language as string. (Using Joomla 2.5)
Re: Get current URL via PHP
Jan 10, 2013 4:15 pm by Edvard
It should return empty string if there is no selected language, since you are not going to add default language code into the URL. After you select a language it will show the selected language. As I understood you are using the plugin for joomla. If you have installed GTranslate Pro general, then you can read this thread: can-always-get-the-language-with-get-t2683.html
Re: Get current URL via PHP
Jan 11, 2013 12:11 am by Dawn
Thanks for your answer. I also checked the linked thread. I've tested it with an url http://www.domain.com/en/ (my default language is german). In the index.php of my template in the header section I use: <?php echo '<!--after this I should see the selected language gtranslate-->'; echo JSession::get('glang'); ?> As I understand you correctly this should output the string "en" - if I access for example http://www.domain.com/en/. Sent you my URL via contact form.
Re: Get current URL via PHP
Jan 11, 2013 3:18 pm by Edvard
Hi, I think you are using the general Pro version and have added the rewrite rules in .htaccess. Please check the mentioned thread and modify the rewrite rules, after that you will be able to access the selected language using $_GET['glang'] variable.
Re: Get current URL via PHP
Jan 11, 2013 3:21 pm by Dawn
Sorry for not answering your questions related to version and .htaccess. I also didn't noticed that there is a changed .htaccess. I'm currently using: # gtranslate config RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/([a-z]{2}|zh-CN|zh-TW)/(.*)$ /$1/$3 [R=301,L] RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/([a-z]{2}|zh-CN|zh-TW)$ /$1/ [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/(.*)$ /gtranslate/translate.php?lang=$1&url=$2 [L,QSA] RewriteRule ^([a-z]{2}|zh-CN|zh-TW)$ /gtranslate/translate.php?lang=$1 [L,QSA] And yes I've got the pro version. I'll try what you've got suggested and give you a feeback. Thanks for the fast answer! EDIT: Saw next to the language related stuff there is a line remove. Do I don't need it with the modified version of the .htaccess? RewriteCond %{REQUEST_FILENAME} !-f
Re: Get current URL via PHP
Jan 11, 2013 3:28 pm by Edvard
It is OK to keep it.
Re: Get current URL via PHP
Jan 11, 2013 3:30 pm by Dawn
It works as you said now! Thanks a lot :)
Re: Get current URL via PHP
Jan 11, 2013 3:36 pm by Edvard
Good to hear that! Thanks for your patience with us.
Re: [Solved] Get current URL via PHP
Jan 11, 2013 3:37 pm by Dawn
Thanks for the good support - I really appreciate it :)

SIMILAR TOPICS

[SOLVED]double dropdownOct 26, 2017 8:26 amReplies: 3Post by: danielesantosubito
[SOLVED] NOT WORKING, HELP PLEASE!Feb 12, 2017 4:53 pmReplies: 5Post by: TSM
Need help <SOLVED>Feb 6, 2017 1:48 pmReplies: 5Post by: blaxx
[solved] edit translations problemDec 15, 2011 10:05 pmReplies: 19Post by: slweb2
[Solved] Main site languageDec 9, 2016 4:39 pmReplies: 4Post by: trench

Try GTranslate with a free 15 day trial