简体   繁体   中英

Joomla site : baseurl does not return correct url

I use Joomla 2.5.7 and I get a problem with $this->baseurl in one page.

In my index.php file, I unclude .js files and .css files with baseurl like in this example :

        <script src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/js/jquery-1.2.6.min.js" type="text/javascript"></script>

And it works fine in this kind of page :

http://mywebsite.com/index.php/myfolder

The page "myfolder" is a list of articles from on category.

And when I click on a article in this page, Joomla use this url :

http://mywebsite.com/index.php/myfolder/article1

And here, all is incorrect (css, js, ...) because my baseurl returns this :

/folder

instead of :

/

And my includes in index.php are not good for this page !

Did you already met this issue ?

How to fix it ?

I didn't find where baseurl is defined, to correct it, can you help me?

Use JURI::root() to get the base root of Joomla

See Joomla Doc page here for further information on it. Also this Joomla forum post - whilst referring to a early RC of Joomla 1.6 might help a bit as well.

OK, thanks for answers but I don't think you clearly understood that I had the problem only with url containing folder.

I found a solution by using live_site variable in configuration.php.

First you build this function at the top of your script

function thisSite($a){
$this_raw = parse_url($a);
$b = preg_replace('#^www\.(.+\.)#i', '$1', $this_raw['host']);
return $b; }

Then you use the function this way

$thisSite = JURI::root();
// $thisSite will echo http://www.mywebsite.com/
$thisSite_base = thisSite($thisSite);
// the function removes http:// and the www and the /path
echo $thisSite_base;

This will echo

mywebsite.com

在模板中,可以使用$this->baseurl快捷方式代替JURI::base( true )

I haven't tested these, but perhaps try one of them:

 JDocument::base
 JDocument::baseurl
 JURI::base()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM