skip to Main Content

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.

6

Answers



  1. 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&param2=value2
    

    In the end, you get :

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

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

    Login or Signup to reply.
  2. In which case you do not want to set $config[‘uri_protocol’] to PATH_INFO. var_dump($_SERVER) somewhere and find which variable contains your path as you want it, then set it to that, if AUTO does not work.

    Login or Signup to reply.
  3. I had the same problem and when i set uri_protocol to PATH_INFO then all the links of my site goes to default controller & action. Then i found that my server doesn’t support PATH_INO variable, so i did two steps in config.php to solve the problem:

    First:

    $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
    

    Then:

    $config['uri_protocol'] = 'PATH_INFO';
    

    The above two lines solve my issue.

    Login or Signup to reply.
  4. The best way is to check which parameter you are getting from the server.

    If you’re getting $_SERVER['PATH_INFO'], use the following.

    $config['uri_protocol'] = 'PATH_INFO';
    

    Otherwise, if you’re getting $_SERVER['ORIG_PATH_INFO'], use this:

    $config['uri_protocol'] = 'ORIG_PATH_INFO';
    

    Make these changes in your config file.

    Login or Signup to reply.
  5. 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.

    This is probably because you’re not actually passing the URL-path as PATH_INFO in your RewriteRule directive:

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

    Here, the URL-path is being passed as a query_string and the path_info is empty (which would explain why all requests end up at your homepage). In this case you would need the additional QSA flag in order to append any additional query string from the request (as noted in your question).

    To pass the URL-path as path_info (ie. additional pathname information), you need to remove the ? from the RewriteRule substitution. (You then don’t need the QSA flag since the query string from the request will be automatically passed through to the substitution.)

    For example, to use PATH_INFO, construct the RewriteRule directive like this:

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

    The regex (.*) is the same as ^(.*)$ since regex is greedy by default.


    Note that your server must also be configured to accept path-info (otherwise it will trigger an automatic 404). By default this is dependent on the associated file handler. The handler associated with .php files will accept path-info by default. (.html files will not.) However, if you need to explicitly enable this then add the following at the top of your .htaccess file:

    AcceptPathInfo On
    

    This enables path-info for all URLs.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search