How to find if Joomla SEF is on or not

2k views Asked by At

I need to find if Joomla's SEF is enabled or not.

To make things worse, Joomla has different SEF mechanisms (see here for more info).

The function I need to fill in is simple:

function rewrite_enabled(){
    return (boolean)$something; // typecast is frivolous
}

The only idea I have so far is:

function rewrite_enabled(){
    $url='index.php?option=com_xyz';
    return JRoute($url)!=$url;
}

Maybe normalizing both URLs (lowercase or by get vars) might make the function a little bit more effective, though it sounds like a big hack, with serious repercussions.

Of course, searched for an answer on Joomla Docs, StackOverflow and Google, without any success. I also inspected Joomla's runtime internals, and but nothing came up.

3

There are 3 answers

2
david.wosnitza On BEST ANSWER

When using Joomla's Core SEF System you could get yourself the config and check if SEF is set to true.

$conf = &JFactory::getConfig();
echo ' SEF is:  '.(($conf->sef == 1) ? 'on' : 'off'); 

(not tested)

Hope it helps a bit. Cheers

For Joomla 3.x you will need:

$conf = &JFactory::getConfig();
echo ' SEF is:  '.(($conf->get('sef') == 1) ? 'on' : 'off'); 
3
ircmaxell On

Just call: JFactory::getConfig():

return (boolean) JFactory::getConfig()->getValue('config.sef', false);
0
Christian On

Well, uh, this is embarasing...

I was looking at some old code of mine and found the following:

$sef = JFactory::getApplication()->getRouter()->getMode()

It does seem to do what I want, though I'm not sure which one's better...

Meh, now it's official, a week into any project, and I forget all about my own code :D