Welcome Guest, Not a member yet? Register   Sign In
URL style PATH_INFO and .htaccess
#1

[eluser]Unknown[/eluser]
Hi guys,

Have a wee bit of a problem, for my application I needed to use query strings to connect with the gowalla.com api. But the way I have it enabled is that you have query strings as well as well formatted links /profile/view/2 etc etc

My problem is that the .htaccess file I was using now does not work, i.e.
// Will show the login page
http://dev.abovefriends.com/index.php/account/login

// Will get to index.php but will only show the root page, the /account/login is not being passed.
http://dev.abovefriends.com/account/login

My config is now setup as so:
Code:
$config['uri_protocol']    = "PATH_INFO";
$config['enable_query_strings'] = TRUE;
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-?';



My original .htaccess file that worked with uri_protocol = "auto" and query strings set to false.
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>


Any help with this is much appreciated, I know the way I have this setup may be a little odd, it is just a shame gowalla cant pass through the information for their api in a post or something.

Regards,
Pete
#2

[eluser]markup2go[/eluser]
Here is how I had success doing the same thing (query strings in url and pretty urls)

Go back to the original .htaccess, which I presume is from the wiki:
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteRule ^(.*)$ index.php?/$1 [L]
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

Not necessary but it might save a headache later to enable more characters in the uri
Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\?\=\#\&\-';

Use PATH_INFO as the protocol:
Code:
$config['uri_protocol']    = "PATH_INFO";

Now, it's been a while and I'm not sure why, but I have query strings disabled:
Code:
$config['enable_query_strings'] = FALSE;

In your controller you'll want to have
Code:
parse_str($_SERVER['QUERY_STRING'],$_GET);

Then you can try to get the query string as necessary
Code:
$var = $this->input->get('var_name')

No guarantee this is going to work for you off the fly but feel free to post your results and I'll see if I can assist further.
#3

[eluser]Unknown[/eluser]
markup2go your are a gent sir! That worked perfectly. I like the idea of parsing the query strings rather than actually having them enabled.. especially as i am just using them for 1 method in gowalla integration.

Cheers,
Pete
#4

[eluser]jostster[/eluser]
I have done this however in my route I have
Code:
$route['clothing/(:any)'] = 'products/index/clothing/$1'

When I check to see what $1 is in the index function it has the querystring still attached to it. Any idea how to get rid of it before passing it to the function?
#5

[eluser]jostster[/eluser]
I also seem to be having an issue with the above configuration.

I copy/pasted that above .htaccess into my .htaccess but the $_SERVER['PATH_INFO'] doesn't work unless i have index.php in my url.

Any ideas?




Theme © iAndrew 2016 - Forum software by © MyBB