Welcome Guest, Not a member yet? Register   Sign In
GET parameters won't work
#1

[eluser]Mr. Pickle[/eluser]
Hi, I'm having a problem with GET parameters (query parameters).
Some external sites (like Google) add a GET parameter when linking to my site, but this is also done by several affiliate programs. For example:
http://www.mysite.com/?gclid=a-string-comes-here (Google)

When loading this URL I get:
404 Page Not Found
The page you requested was not found.
while loading http://www.mysite.com/ loads ok.

I know because of security reasons CI does not allow query parameters.
For other sites I have found a solution in:

1. Removing the ? from the htaccess rewriterule;
2. Set uri_protocol to PATH_INFO (instead of default AUTO);
3. Leaving the enable_query_strings to FALSE.

I have even got this working local for this project. But for some reason when publishing the code to my server it does not work anymore. Setting PATH_INFO results in having all my pages load the default controller (as if CI does not read the full url anymore)
Removing the ? from the htaccess also troubles it completely.

For info, the server runs on Ubuntu with Apache 2.2.8

At this moment I got back to default settings (and thus with a non-working site if query param is present)

My current .htaccess:
Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L]

My current config.php contains (only those applicable on this issue)

Code:
$config['index_page'] = "";

$config['uri_protocol']    = "AUTO";

$config['enable_query_strings'] = FALSE;
#2

[eluser]cahva[/eluser]
With mod_php query strings will work with PATH_INFO and enable_query_strings set to TRUE. I quess you have PHP run as CGI in other server and it wont work there. Check this thread for advice how to get GET work also on CGI:
http://ellislab.com/forums/viewthread/96347/
#3

[eluser]pbreit[/eluser]
Try this as outlined in this thread:
http://ellislab.com/forums/viewthread/159382/

Code:
class MY_Input extends CI_Input
{
    function _sanitize_globals()
    {
        $this->allow_get_array = TRUE;
        parent::_sanitize_globals();
    }
}

Note: this should work with a normal .htaccess file and default configs.
#4

[eluser]Mr. Pickle[/eluser]
[quote author="pbreit" date="1284010566"]Try this as outlined in this thread:
http://ellislab.com/forums/viewthread/159382/

Code:
class MY_Input extends CI_Input
{
    function _sanitize_globals()
    {
        $this->allow_get_array = TRUE;
        parent::_sanitize_globals();
    }
}

Note: this should work with a normal .htaccess file and default configs.[/quote]

Hi, unfortunately this doesn't help. I made MY_Input.php and put it in the libraries folder of my application folder. The site still works but CI gives the '404' error if you add a query parameter.

Just to be clear, I do not want to use the query params I just want the site to work (and rather ignore) them but leave them in the url so Google and affiliate systems can do with it what they want.
#5

[eluser]Mr. Pickle[/eluser]
And yes, the production environment has CGI as PHP server API, which might explain the different behavior with other servers I worked on (having Apache as PHP server API)
#6

[eluser]Mr. Pickle[/eluser]
The solution on http://ellislab.com/forums/viewthread/96347/ works for me.

This contains:

Changing the following 2 lines in the config.php file:

1.
Code:
$config['uri_protocol'] = "AUTO";
to:
Code:
$config['uri_protocol'] = "APP_PATH";


2.
Code:
$config['enable_query_strings'] = FALSE;
to:
Code:
$config['enable_query_strings'] = TRUE;


And setting the following .htaccess file:

Code:
RewriteEngine On

RewriteBase /

RewriteCond %{ENV:REDIRECT_APP_PATH} !^$
RewriteRule ^(.*)$ - [E=APP_PATH:%{ENV:REDIRECT_APP_PATH}]

RewriteCond %{ENV:APP_PATH} ^$
RewriteRule ^(.*)$ - [E=APP_PATH:/$1]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]

Only thing is I don't yet understand what I've done/set with the new htaccess and if/how this will effect my application.




Theme © iAndrew 2016 - Forum software by © MyBB