Jump to content

Problem with Tag Meta, front page of site, and S2 framework


Stephen Brandon

Recommended Posts

Hi,

 

I was tracking down a problem with Tag Meta being unable to detect the front page of a Joomla site.

 

Joomla 1.5.22

Tag Meta 1.3 community - http://www.sistemistica.it/tag-meta.html

Joomla SEF URLs turned on (built-in SEF)

JReviews 2.2.04.178

 

The symptoms were that Tag Meta was able to deduce the URL for every page apart from the front page. e.g. it could detect /articles, /foo, /bar etc. But on the front page of the site it detected "/index.php?" which is clearly not the real url (http://localhost/)

 

I tracked this down to the dispatcher in the S2 framework.

 

The dispatcher includes a piece of code that is intended to fix issues with IIS. It attempts to recreate the $_SERVER['REQUEST_URI'] variable which IIS does not otherwise provide.

 

The symptoms of the problem that this causes are that the front page of the site, instead of getting a REQUEST_URI of "/", gets "/index.php?", at least on my local copy of Apache.

 

The code is in the getUri() method, which is a copy of the code from http://neosmart.net/blog/2006/100-apache-compliant-request_uri-for-iis-and-windows/

 

There are several problems with it (apart from the obvious which is "it mangles the URL of the front page":

 

1 - the neosmart code is designed to be used *preferably* in conjunction with some sort of plugin on the IIS server itself. This evidently sets the HTTP_REQUEST_URI header, then the neosmart PHP code picks this up and uses it for the URL.

 

2 - it seems to get run more than once per page. The original code from neosmart was only intended to get run once per page. If you look at the code you can see that the 1st time it is run, $_SERVER['HTTP_REQUEST_URI'] gets set (which is not a standard Apache header, at least on my machine).

The second time it is run on the same page, the $_SERVER['HTTP_REQUEST_URI'] header is detected and taken as evidence that IIS was installed, and this gets put into REQUEST_URI. By this stage, for the front page it's the wrong URL...

 

The code explicitly states that it works best when ISAPI_Rewrite is installed, and is not guaranteed to work if it's not:

 

	    //ISAPI_Rewrite isn't installed or not configured
    else{
        //Someone didn't follow the instructions!
        if(isset($_SERVER['SCRIPT_NAME']))
            $_SERVER['HTTP_REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
        else
            $_SERVER['HTTP_REQUEST_URI'] = $_SERVER['PHP_SELF'];
        if(isset($_SERVER['QUERY_STRING'])){
            $_SERVER['HTTP_REQUEST_URI'] .=  '?' . $_SERVER['QUERY_STRING'];
        }
        //WARNING: This is a workaround!
        //For guaranteed compatibility, HTTP_REQUEST_URI or HTTP_X_REWRITE_URL *MUST* be defined!
        //See product documentation for instructions!
        $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_REQUEST_URI'];
    }

3 - in that last portion of code you can see that the script name (index.php) is picked up, appended with "?" since QUERY_STRING is available (though empty), and we end up with "index.php?".

 

 

Now, I haven't worked out exactly how this is picking up index.php instead of the SEF URL, when on the front page in Joomla. But it's clearly coming up with the wrong value, and that no doubt causes problems within JReviews.

 

Furthermore, since it's altering a core server variable, it has the potential to affect many other extensions in Joomla - and is already affecting Tag Meta.

 

- Can you do without this code?

- Is there any other way to determine whether IIS is being used? Then you would only need to run this portion of code if it was really necessary, and you could prompt admins to install that other dll thing to make it work properly.

 

The simple workaround to make this work, for anyone on Apache, is to comment out this line from the file:

 

// Fixed REQUEST_URI for IIS

// $this->getUri();

 

 

Cheers,

Stephen Brandon

metamodpro.com

Link to comment
×
×
  • Create New...