views:

842

answers:

2

I need to change $config['uri_protocol'] from AUTO to PATH_INFO (to allow url parameters)

My problem: when I set $config['uri_protocol']="PATH_INFO"; the regular urls stop functioning and I get the homepage no matter which site page URL I click.

print_r ($_SERVER) shows that url parameters I add appear only in REQUEST_URI an not in any other $_SERVER part.

my htaccess is the standard one

<IfModule mod_rewrite.c>
    RewriteEngine On

    # This is different between local host and production server!!!
    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]

    #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>

UPDATE:

I changed

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

to RewriteRule ^(.*)$ index.php?/$1 [QSA,L] to allow url params to pass. Now url params appear also in

 $_SERVER

 REDIRECT_QUERY_STRING, QUERY_STRING AND REQUEST_URI

.

The problem: I tried $config[‘uri_protocol’] with all the above options but still CI gives error 404 whenever I add URL parameters.

Note: I tried the above on 2 servers. One of them is centos5/Apache2/Plesk VPS and another one is on xampp/Vista.

+1  A: 

You should probably use the [QSA] option in your last rule from mod_rewrite... This appends the query string arguments (I mean after the '?') to your final URL.

Your rule ends like this :

RewriteRule ^(.*)$ index.php?baseurl=$1 [QSA,L]

If your request is :

http://yourhost.com/module/action?param1=value1&amp;param2=value2

In the end, you get :

http://yourhost.com/index.php?baseurl=/module/action&amp;param1=value1&amp;param2=value2

I haven't tested it. Is it what you really want ?

Arno
Hi Arno,Thanks for the tip. It did not solve the problem completely, please see the update in the original question.
Nir
Have you tried to remove the trailing slash between "?" and "$1" ?
Arno
+1  A: 

http://stackoverflow.com/questions/1880807/how-to-remove-url-parameters-in-htaccess

Nir
Hey, I just found this question through Google. I'm having exactly the same problem that you describe here. I need to use URL query strings but if I change $config[‘uri_protocol’] to "PATH_INFO" (which is needed to allow the query string to work), all of my pages simply redirect to the home page.Now I followed your link that you've supplied here but I don't understand your solution (and it doesn't seem to work for me). Can I ask what did you set $config[‘uri_protocol’] to and what does your .htaccess look like now?Thanks a lot. :)
sixfoottallrabbit
Sorry about that, I figured out a solution (hack hack hack :P). My host (for some reason) doesn't allow the PATH_INFO variable. So I just copied the ORIG_PATH_INFO value into the PATH_INFO variable. Et voila!
sixfoottallrabbit